neulab/docprompting-conala huggingface dataset:
InlineModelAdmin.extra  
This controls the number of extra forms the formset will display in addition to the initial forms. Defaults to 3. See the formsets documentation for more information. For users with JavaScript-enabled browsers, an “Add another” link is provided to enable any number of additional inlines to be added in addition to those provided as a result of the extra argument. The dynamic link will not appear if the number of currently displayed forms exceeds max_num, or if the user does not have JavaScript enabled. InlineModelAdmin.get_extra() also allows you to customize the number of extra forms.
InlineModelAdmin.fk_name  
The name of the foreign key on the model. In most cases this will be dealt with automatically, but fk_name must be specified explicitly if there are more than one foreign key to the same parent model.
InlineModelAdmin.form  
The value for form defaults to ModelForm. This is what is passed through to inlineformset_factory() when creating the formset for this inline.
InlineModelAdmin.formset  
This defaults to BaseInlineFormSet. Using your own formset can give you many possibilities of customization. Inlines are built around model formsets.
InlineModelAdmin.get_extra(request, obj=None, **kwargs)  
Returns the number of extra inline forms to use. By default, returns the InlineModelAdmin.extra attribute. Override this method to programmatically determine the number of extra inline forms. For example, this may be based on the model instance (passed as the keyword argument obj): class BinaryTreeAdmin(admin.TabularInline):
    model = BinaryTree

    def get_extra(self, request, obj=None, **kwargs):
        extra = 2
        if obj:
            return extra - obj.binarytree_set.count()
        return extra
InlineModelAdmin.get_formset(request, obj=None, **kwargs)  
Returns a BaseInlineFormSet class for use in admin add/change views. obj is the parent object being edited or None when adding a new parent. See the example for ModelAdmin.get_formsets_with_inlines.
InlineModelAdmin.get_max_num(request, obj=None, **kwargs)  
Returns the maximum number of extra inline forms to use. By default, returns the InlineModelAdmin.max_num attribute. Override this method to programmatically determine the maximum number of inline forms. For example, this may be based on the model instance (passed as the keyword argument obj): class BinaryTreeAdmin(admin.TabularInline):
    model = BinaryTree

    def get_max_num(self, request, obj=None, **kwargs):
        max_num = 10
        if obj and obj.parent:
            return max_num - 5
        return max_num
InlineModelAdmin.get_min_num(request, obj=None, **kwargs)  
Returns the minimum number of inline forms to use. By default, returns the InlineModelAdmin.min_num attribute. Override this method to programmatically determine the minimum number of inline forms. For example, this may be based on the model instance (passed as the keyword argument obj).
InlineModelAdmin.has_add_permission(request, obj)  
Should return True if adding an inline object is permitted, False otherwise. obj is the parent object being edited or None when adding a new parent.
InlineModelAdmin.has_change_permission(request, obj=None)  
Should return True if editing an inline object is permitted, False otherwise. obj is the parent object being edited.
InlineModelAdmin.has_delete_permission(request, obj=None)  
Should return True if deleting an inline object is permitted, False otherwise. obj is the parent object being edited.
InlineModelAdmin.max_num  
This controls the maximum number of forms to show in the inline. This doesn’t directly correlate to the number of objects, but can if the value is small enough. See Limiting the number of editable objects for more information. InlineModelAdmin.get_max_num() also allows you to customize the maximum number of extra forms.
InlineModelAdmin.min_num  
This controls the minimum number of forms to show in the inline. See modelformset_factory() for more information. InlineModelAdmin.get_min_num() also allows you to customize the minimum number of displayed forms.
InlineModelAdmin.raw_id_fields  
By default, Django’s admin uses a select-box interface (<select>) for fields that are ForeignKey. Sometimes you don’t want to incur the overhead of having to select all the related instances to display in the drop-down. raw_id_fields is a list of fields you would like to change into an Input widget for either a ForeignKey or ManyToManyField: class BookInline(admin.TabularInline):
    model = Book
    raw_id_fields = ("pages",)
InlineModelAdmin.show_change_link  
Specifies whether or not inline objects that can be changed in the admin have a link to the change form. Defaults to False.
InlineModelAdmin.verbose_name  
An override to the verbose_name from the model’s inner Meta class.
InlineModelAdmin.verbose_name_plural  
An override to the verbose_name_plural from the model’s inner Meta class. If this isn’t given and the InlineModelAdmin.verbose_name is defined, Django will use InlineModelAdmin.verbose_name + 's'.  Changed in Django 4.0: The fallback to InlineModelAdmin.verbose_name was added.
class ModelAdmin  
The ModelAdmin class is the representation of a model in the admin interface. Usually, these are stored in a file named admin.py in your application. Let’s take a look at an example of the ModelAdmin: from django.contrib import admin
from myapp.models import Author

class AuthorAdmin(admin.ModelAdmin):
    pass
admin.site.register(Author, AuthorAdmin)
  Do you need a ModelAdmin object at all? In the preceding example, the ModelAdmin class doesn’t define any custom values (yet). As a result, the default admin interface will be provided. If you are happy with the default admin interface, you don’t need to define a ModelAdmin object at all – you can register the model class without providing a ModelAdmin description. The preceding example could be simplified to: from django.contrib import admin
from myapp.models import Author

admin.site.register(Author)
ModelAdmin.actions  
A list of actions to make available on the change list page. See Admin actions for details.
ModelAdmin.actions_on_bottom  
Controls where on the page the actions bar appears. By default, the admin changelist displays actions at the top of the page (actions_on_top = True;
actions_on_bottom = False).
ModelAdmin.actions_selection_counter  
Controls whether a selection counter is displayed next to the action dropdown. By default, the admin changelist will display it (actions_selection_counter = True).
ModelAdmin.add_form_template  
Path to a custom template, used by add_view().
ModelAdmin.add_view(request, form_url='', extra_context=None)  
Django view for the model instance addition page. See note below.
ModelAdmin.autocomplete_fields  
autocomplete_fields is a list of ForeignKey and/or ManyToManyField fields you would like to change to Select2 autocomplete inputs. By default, the admin uses a select-box interface (<select>) for those fields. Sometimes you don’t want to incur the overhead of selecting all the related instances to display in the dropdown. The Select2 input looks similar to the default input but comes with a search feature that loads the options asynchronously. This is faster and more user-friendly if the related model has many instances. You must define search_fields on the related object’s ModelAdmin because the autocomplete search uses it. To avoid unauthorized data disclosure, users must have the view or change permission to the related object in order to use autocomplete. Ordering and pagination of the results are controlled by the related ModelAdmin’s get_ordering() and get_paginator() methods. In the following example, ChoiceAdmin has an autocomplete field for the ForeignKey to the Question. The results are filtered by the question_text field and ordered by the date_created field: class QuestionAdmin(admin.ModelAdmin):
    ordering = ['date_created']
    search_fields = ['question_text']

class ChoiceAdmin(admin.ModelAdmin):
    autocomplete_fields = ['question']
  Performance considerations for large datasets Ordering using ModelAdmin.ordering may cause performance problems as sorting on a large queryset will be slow. Also, if your search fields include fields that aren’t indexed by the database, you might encounter poor performance on extremely large tables. For those cases, it’s a good idea to write your own ModelAdmin.get_search_results() implementation using a full-text indexed search. You may also want to change the Paginator on very large tables as the default paginator always performs a count() query. For example, you could override the default implementation of the Paginator.count property.
ModelAdmin.change_form_template  
Path to a custom template, used by change_view().
ModelAdmin.change_list_template  
Path to a custom template, used by changelist_view().
ModelAdmin.change_view(request, object_id, form_url='', extra_context=None)  
Django view for the model instance editing page. See note below.
ModelAdmin.changelist_view(request, extra_context=None)  
Django view for the model instances change list/actions page. See note below.
ModelAdmin.date_hierarchy  
Set date_hierarchy to the name of a DateField or DateTimeField in your model, and the change list page will include a date-based drilldown navigation by that field. Example: date_hierarchy = 'pub_date'
 You can also specify a field on a related model using the __ lookup, for example: date_hierarchy = 'author__pub_date'
 This will intelligently populate itself based on available data, e.g. if all the dates are in one month, it’ll show the day-level drill-down only.  Note date_hierarchy uses QuerySet.datetimes() internally. Please refer to its documentation for some caveats when time zone support is enabled (USE_TZ = True).
ModelAdmin.delete_confirmation_template  
Path to a custom template, used by delete_view() for displaying a confirmation page when deleting one or more objects.
ModelAdmin.delete_model(request, obj)  
The delete_model method is given the HttpRequest and a model instance. Overriding this method allows doing pre- or post-delete operations. Call super().delete_model() to delete the object using Model.delete().
ModelAdmin.delete_queryset(request, queryset)  
The delete_queryset() method is given the HttpRequest and a QuerySet of objects to be deleted. Override this method to customize the deletion process for the “delete selected objects” action.
ModelAdmin.delete_selected_confirmation_template  
Path to a custom template, used by the delete_selected action method for displaying a confirmation page when deleting one or more objects. See the actions documentation.
ModelAdmin.delete_view(request, object_id, extra_context=None)  
Django view for the model instance(s) deletion confirmation page. See note below.
ModelAdmin.empty_value_display  
This attribute overrides the default display value for record’s fields that are empty (None, empty string, etc.). The default value is - (a dash). For example: from django.contrib import admin

class AuthorAdmin(admin.ModelAdmin):
    empty_value_display = '-empty-'
 You can also override empty_value_display for all admin pages with AdminSite.empty_value_display, or for specific fields like this: from django.contrib import admin

class AuthorAdmin(admin.ModelAdmin):
    fields = ('name', 'title', 'view_birth_date')

    @admin.display(empty_value='???')
    def view_birth_date(self, obj):
        return obj.birth_date
  Changed in Django 3.2: The empty_value argument to the display() decorator is equivalent to setting the empty_value_display attribute on the display function directly in previous versions. Setting the attribute directly is still supported for backward compatibility.
ModelAdmin.exclude  
This attribute, if given, should be a list of field names to exclude from the form. For example, let’s consider the following model: from django.db import models

class Author(models.Model):
    name = models.CharField(max_length=100)
    title = models.CharField(max_length=3)
    birth_date = models.DateField(blank=True, null=True)
 If you want a form for the Author model that includes only the name and title fields, you would specify fields or exclude like this: from django.contrib import admin

class AuthorAdmin(admin.ModelAdmin):
    fields = ('name', 'title')

class AuthorAdmin(admin.ModelAdmin):
    exclude = ('birth_date',)
 Since the Author model only has three fields, name, title, and birth_date, the forms resulting from the above declarations will contain exactly the same fields.
ModelAdmin.fields  
Use the fields option to make simple layout changes in the forms on the “add” and “change” pages such as showing only a subset of available fields, modifying their order, or grouping them into rows. For example, you could define a simpler version of the admin form for the django.contrib.flatpages.models.FlatPage model as follows: class FlatPageAdmin(admin.ModelAdmin):
    fields = ('url', 'title', 'content')
 In the above example, only the fields url, title and content will be displayed, sequentially, in the form. fields can contain values defined in ModelAdmin.readonly_fields to be displayed as read-only. For more complex layout needs, see the fieldsets option. The fields option accepts the same types of values as list_display, except that callables aren’t accepted. Names of model and model admin methods will only be used if they’re listed in readonly_fields. To display multiple fields on the same line, wrap those fields in their own tuple. In this example, the url and title fields will display on the same line and the content field will be displayed below them on its own line: class FlatPageAdmin(admin.ModelAdmin):
    fields = (('url', 'title'), 'content')
  Note This fields option should not be confused with the fields dictionary key that is within the fieldsets option, as described in the next section.  If neither fields nor fieldsets options are present, Django will default to displaying each field that isn’t an AutoField and has editable=True, in a single fieldset, in the same order as the fields are defined in the model.
ModelAdmin.fieldsets  
Set fieldsets to control the layout of admin “add” and “change” pages. fieldsets is a list of two-tuples, in which each two-tuple represents a <fieldset> on the admin form page. (A <fieldset> is a “section” of the form.) The two-tuples are in the format (name, field_options), where name is a string representing the title of the fieldset and field_options is a dictionary of information about the fieldset, including a list of fields to be displayed in it. A full example, taken from the django.contrib.flatpages.models.FlatPage model: from django.contrib import admin

class FlatPageAdmin(admin.ModelAdmin):
    fieldsets = (
        (None, {
            'fields': ('url', 'title', 'content', 'sites')
        }),
        ('Advanced options', {
            'classes': ('collapse',),
            'fields': ('registration_required', 'template_name'),
        }),
    )
 This results in an admin page that looks like:  If neither fieldsets nor fields options are present, Django will default to displaying each field that isn’t an AutoField and has editable=True, in a single fieldset, in the same order as the fields are defined in the model. The field_options dictionary can have the following keys:  
 
fields  
A tuple of field names to display in this fieldset. This key is required. Example: {
'fields': ('first_name', 'last_name', 'address', 'city', 'state'),
}
 As with the fields option, to display multiple fields on the same line, wrap those fields in their own tuple. In this example, the first_name and last_name fields will display on the same line: {
'fields': (('first_name', 'last_name'), 'address', 'city', 'state'),
}
 fields can contain values defined in readonly_fields to be displayed as read-only. If you add the name of a callable to fields, the same rule applies as with the fields option: the callable must be listed in readonly_fields.    
 
classes  
A list or tuple containing extra CSS classes to apply to the fieldset. Example: {
'classes': ('wide', 'extrapretty'),
}
 Two useful classes defined by the default admin site stylesheet are collapse and wide. Fieldsets with the collapse style will be initially collapsed in the admin and replaced with a small “click to expand” link. Fieldsets with the wide style will be given extra horizontal space.    
 
description  
A string of optional extra text to be displayed at the top of each fieldset, under the heading of the fieldset. This string is not rendered for TabularInline due to its layout. Note that this value is not HTML-escaped when it’s displayed in the admin interface. This lets you include HTML if you so desire. Alternatively you can use plain text and django.utils.html.escape() to escape any HTML special characters.
ModelAdmin.filter_horizontal  
By default, a ManyToManyField is displayed in the admin site with a <select multiple>. However, multiple-select boxes can be difficult to use when selecting many items. Adding a ManyToManyField to this list will instead use a nifty unobtrusive JavaScript “filter” interface that allows searching within the options. The unselected and selected options appear in two boxes side by side. See filter_vertical to use a vertical interface.
ModelAdmin.filter_vertical  
Same as filter_horizontal, but uses a vertical display of the filter interface with the box of unselected options appearing above the box of selected options.
ModelAdmin.form  
By default a ModelForm is dynamically created for your model. It is used to create the form presented on both the add/change pages. You can easily provide your own ModelForm to override any default form behavior on the add/change pages. Alternatively, you can customize the default form rather than specifying an entirely new one by using the ModelAdmin.get_form() method. For an example see the section Adding custom validation to the admin.  Note If you define the Meta.model attribute on a ModelForm, you must also define the Meta.fields attribute (or the Meta.exclude attribute). However, since the admin has its own way of defining fields, the Meta.fields attribute will be ignored. If the ModelForm is only going to be used for the admin, the easiest solution is to omit the Meta.model attribute, since ModelAdmin will provide the correct model to use. Alternatively, you can set fields = [] in the Meta class to satisfy the validation on the ModelForm.   Note If your ModelForm and ModelAdmin both define an exclude option then ModelAdmin takes precedence: from django import forms
from django.contrib import admin
from myapp.models import Person

class PersonForm(forms.ModelForm):

    class Meta:
        model = Person
        exclude = ['name']

class PersonAdmin(admin.ModelAdmin):
    exclude = ['age']
    form = PersonForm
 In the above example, the “age” field will be excluded but the “name” field will be included in the generated form.
ModelAdmin.formfield_for_choice_field(db_field, request, **kwargs)  
Like the formfield_for_foreignkey and formfield_for_manytomany methods, the formfield_for_choice_field method can be overridden to change the default formfield for a field that has declared choices. For example, if the choices available to a superuser should be different than those available to regular staff, you could proceed as follows: class MyModelAdmin(admin.ModelAdmin):
    def formfield_for_choice_field(self, db_field, request, **kwargs):
        if db_field.name == "status":
            kwargs['choices'] = (
                ('accepted', 'Accepted'),
                ('denied', 'Denied'),
            )
            if request.user.is_superuser:
                kwargs['choices'] += (('ready', 'Ready for deployment'),)
        return super().formfield_for_choice_field(db_field, request, **kwargs)
  Note Any choices attribute set on the formfield will be limited to the form field only. If the corresponding field on the model has choices set, the choices provided to the form must be a valid subset of those choices, otherwise the form submission will fail with a ValidationError when the model itself is validated before saving.
ModelAdmin.formfield_for_foreignkey(db_field, request, **kwargs)  
The formfield_for_foreignkey method on a ModelAdmin allows you to override the default formfield for a foreign keys field. For example, to return a subset of objects for this foreign key field based on the user: class MyModelAdmin(admin.ModelAdmin):
    def formfield_for_foreignkey(self, db_field, request, **kwargs):
        if db_field.name == "car":
            kwargs["queryset"] = Car.objects.filter(owner=request.user)
        return super().formfield_for_foreignkey(db_field, request, **kwargs)
 This uses the HttpRequest instance to filter the Car foreign key field to only display the cars owned by the User instance. For more complex filters, you can use ModelForm.__init__() method to filter based on an instance of your model (see Fields which handle relationships). For example: class CountryAdminForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['capital'].queryset = self.instance.cities.all()

class CountryAdmin(admin.ModelAdmin):
    form = CountryAdminForm
ModelAdmin.formfield_for_manytomany(db_field, request, **kwargs)  
Like the formfield_for_foreignkey method, the formfield_for_manytomany method can be overridden to change the default formfield for a many to many field. For example, if an owner can own multiple cars and cars can belong to multiple owners – a many to many relationship – you could filter the Car foreign key field to only display the cars owned by the User: class MyModelAdmin(admin.ModelAdmin):
    def formfield_for_manytomany(self, db_field, request, **kwargs):
        if db_field.name == "cars":
            kwargs["queryset"] = Car.objects.filter(owner=request.user)
        return super().formfield_for_manytomany(db_field, request, **kwargs)
ModelAdmin.formfield_overrides  
This provides a quick-and-dirty way to override some of the Field options for use in the admin. formfield_overrides is a dictionary mapping a field class to a dict of arguments to pass to the field at construction time. Since that’s a bit abstract, let’s look at a concrete example. The most common use of formfield_overrides is to add a custom widget for a certain type of field. So, imagine we’ve written a RichTextEditorWidget that we’d like to use for large text fields instead of the default <textarea>. Here’s how we’d do that: from django.contrib import admin
from django.db import models

# Import our custom widget and our model from where they're defined
from myapp.models import MyModel
from myapp.widgets import RichTextEditorWidget

class MyModelAdmin(admin.ModelAdmin):
    formfield_overrides = {
        models.TextField: {'widget': RichTextEditorWidget},
    }
 Note that the key in the dictionary is the actual field class, not a string. The value is another dictionary; these arguments will be passed to the form field’s __init__() method. See The Forms API for details.  Warning If you want to use a custom widget with a relation field (i.e. ForeignKey or ManyToManyField), make sure you haven’t included that field’s name in raw_id_fields, radio_fields, or autocomplete_fields. formfield_overrides won’t let you change the widget on relation fields that have raw_id_fields, radio_fields, or autocomplete_fields set. That’s because raw_id_fields, radio_fields, and autocomplete_fields imply custom widgets of their own.
ModelAdmin.get_actions(request)  
Finally, you can conditionally enable or disable actions on a per-request (and hence per-user basis) by overriding ModelAdmin.get_actions(). This returns a dictionary of actions allowed. The keys are action names, and the values are (function, name, short_description) tuples. For example, if you only want users whose names begin with ‘J’ to be able to delete objects in bulk: class MyModelAdmin(admin.ModelAdmin):
    ...

    def get_actions(self, request):
        actions = super().get_actions(request)
        if request.user.username[0].upper() != 'J':
            if 'delete_selected' in actions:
                del actions['delete_selected']
        return actions