diff options
| author | Alex Morega <alex@grep.ro> | 2022-08-26 17:10:27 +0300 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-08-30 09:57:17 +0200 |
| commit | de6c9c70549010fc39509f9ef3f6a62ada870318 (patch) | |
| tree | fc0206ae8cd3fc3d7a78e76b6ae3e95f4e0505b1 /docs/ref | |
| parent | b3db6c8dcb5145f7d45eff517bcd96460475c879 (diff) | |
Refs #30947 -- Changed tuples to lists where appropriate.
Diffstat (limited to 'docs/ref')
| -rw-r--r-- | docs/ref/contrib/admin/filters.txt | 22 | ||||
| -rw-r--r-- | docs/ref/contrib/admin/index.txt | 90 | ||||
| -rw-r--r-- | docs/ref/contrib/flatpages.txt | 12 | ||||
| -rw-r--r-- | docs/ref/contrib/gis/serializers.txt | 2 | ||||
| -rw-r--r-- | docs/ref/contrib/postgres/constraints.txt | 4 | ||||
| -rw-r--r-- | docs/ref/contrib/syndication.txt | 6 | ||||
| -rw-r--r-- | docs/ref/models/instances.txt | 4 |
7 files changed, 70 insertions, 70 deletions
diff --git a/docs/ref/contrib/admin/filters.txt b/docs/ref/contrib/admin/filters.txt index 0dc119af3f..a3d7bfc9cd 100644 --- a/docs/ref/contrib/admin/filters.txt +++ b/docs/ref/contrib/admin/filters.txt @@ -33,13 +33,13 @@ Each specified field should be either a ``BooleanField``, ``CharField``, ``ManyToManyField``, for example:: class PersonAdmin(admin.ModelAdmin): - list_filter = ('is_staff', 'company') + list_filter = ['is_staff', 'company'] Field names in ``list_filter`` can also span relations using the ``__`` lookup, for example:: class PersonAdmin(admin.UserAdmin): - list_filter = ('company__name',) + list_filter = ['company__name'] Using a ``SimpleListFilter`` ============================ @@ -70,10 +70,10 @@ and ``parameter_name`` attributes, and override the ``lookups`` and human-readable name for the option that will appear in the right sidebar. """ - return ( + return [ ('80s', _('in the eighties')), ('90s', _('in the nineties')), - ) + ] def queryset(self, request, queryset): """ @@ -95,7 +95,7 @@ and ``parameter_name`` attributes, and override the ``lookups`` and ) class PersonAdmin(admin.ModelAdmin): - list_filter = (DecadeBornListFilter,) + list_filter = [DecadeBornListFilter] .. note:: @@ -144,9 +144,9 @@ field name and the second element is a class inheriting from ``django.contrib.admin.FieldListFilter``, for example:: class PersonAdmin(admin.ModelAdmin): - list_filter = ( + list_filter = [ ('is_staff', admin.BooleanFieldListFilter), - ) + ] Here the ``is_staff`` field will use the ``BooleanFieldListFilter``. Specifying only the field name, fields will automatically use the appropriate filter for @@ -159,9 +159,9 @@ You can limit the choices of a related model to the objects involved in that relation using ``RelatedOnlyFieldListFilter``:: class BookAdmin(admin.ModelAdmin): - list_filter = ( + list_filter = [ ('author', admin.RelatedOnlyFieldListFilter), - ) + ] Assuming ``author`` is a ``ForeignKey`` to a ``User`` model, this will limit the ``list_filter`` choices to the users who have written a book, @@ -172,9 +172,9 @@ filter on both empty strings and nulls, depending on what the field allows to store:: class BookAdmin(admin.ModelAdmin): - list_filter = ( + list_filter = [ ('title', admin.EmptyFieldListFilter), - ) + ] By defining a filter using the ``__in`` lookup, it is possible to filter for any of a group of values. You need to override the ``expected_parameters`` diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt index e77a00e2db..4da7a9691a 100644 --- a/docs/ref/contrib/admin/index.txt +++ b/docs/ref/contrib/admin/index.txt @@ -249,7 +249,7 @@ subclass:: from django.contrib import admin class AuthorAdmin(admin.ModelAdmin): - list_display = ('name', 'title', 'view_birth_date') + list_display = ['name', 'title', 'view_birth_date'] @admin.display(empty_value='???') def view_birth_date(self, obj): @@ -276,10 +276,10 @@ subclass:: from django.contrib import admin class AuthorAdmin(admin.ModelAdmin): - fields = ('name', 'title') + fields = ['name', 'title'] class AuthorAdmin(admin.ModelAdmin): - exclude = ('birth_date',) + exclude = ['birth_date'] Since the Author model only has three fields, ``name``, ``title``, and ``birth_date``, the forms resulting from the above declarations will @@ -294,7 +294,7 @@ subclass:: :class:`django.contrib.flatpages.models.FlatPage` model as follows:: class FlatPageAdmin(admin.ModelAdmin): - fields = ('url', 'title', 'content') + 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 @@ -314,7 +314,7 @@ subclass:: own line:: class FlatPageAdmin(admin.ModelAdmin): - fields = (('url', 'title'), 'content') + fields = [('url', 'title'), 'content'] .. admonition:: Note @@ -346,15 +346,15 @@ subclass:: from django.contrib import admin class FlatPageAdmin(admin.ModelAdmin): - fieldsets = ( + fieldsets = [ (None, { - 'fields': ('url', 'title', 'content', 'sites') + 'fields': ['url', 'title', 'content', 'sites'], }), ('Advanced options', { - 'classes': ('collapse',), - 'fields': ('registration_required', 'template_name'), + 'classes': ['collapse'], + 'fields': ['registration_required', 'template_name'], }), - ) + ] This results in an admin page that looks like: @@ -368,13 +368,13 @@ subclass:: The ``field_options`` dictionary can have the following keys: * ``fields`` - A tuple of field names to display in this fieldset. This key is + A list or tuple of field names to display in this fieldset. This key is required. Example:: { - 'fields': ('first_name', 'last_name', 'address', 'city', 'state'), + 'fields': ['first_name', 'last_name', 'address', 'city', 'state'], } As with the :attr:`~ModelAdmin.fields` option, to display multiple @@ -383,7 +383,7 @@ subclass:: the same line:: { - 'fields': (('first_name', 'last_name'), 'address', 'city', 'state'), + 'fields': [('first_name', 'last_name'), 'address', 'city', 'state'], } ``fields`` can contain values defined in @@ -399,7 +399,7 @@ subclass:: Example:: { - 'classes': ('wide', 'extrapretty'), + 'classes': ['wide', 'extrapretty'], } Two useful classes defined by the default admin site stylesheet are @@ -540,7 +540,7 @@ subclass:: Example:: - list_display = ('first_name', 'last_name') + list_display = ['first_name', 'last_name'] If you don't set ``list_display``, the admin site will display a single column that displays the ``__str__()`` representation of each object. @@ -552,7 +552,7 @@ subclass:: * The name of a model field. For example:: class PersonAdmin(admin.ModelAdmin): - list_display = ('first_name', 'last_name') + list_display = ['first_name', 'last_name'] * A callable that accepts one argument, the model instance. For example:: @@ -561,13 +561,13 @@ subclass:: return ("%s %s" % (obj.first_name, obj.last_name)).upper() class PersonAdmin(admin.ModelAdmin): - list_display = (upper_case_name,) + list_display = [upper_case_name] * A string representing a ``ModelAdmin`` method that accepts one argument, the model instance. For example:: class PersonAdmin(admin.ModelAdmin): - list_display = ('upper_case_name',) + list_display = ['upper_case_name'] @admin.display(description='Name') def upper_case_name(self, obj): @@ -588,7 +588,7 @@ subclass:: return '%d’s' % (self.birthday.year // 10 * 10) class PersonAdmin(admin.ModelAdmin): - list_display = ('name', 'decade_born_in') + list_display = ['name', 'decade_born_in'] A few special cases to note about ``list_display``: @@ -630,7 +630,7 @@ subclass:: ) class PersonAdmin(admin.ModelAdmin): - list_display = ('first_name', 'last_name', 'colored_name') + list_display = ['first_name', 'last_name', 'colored_name'] * As some examples have already demonstrated, when using a callable, a model method, or a ``ModelAdmin`` method, you can customize the column's @@ -654,7 +654,7 @@ subclass:: Or on a field level:: class PersonAdmin(admin.ModelAdmin): - list_display = ('name', 'birth_date_view') + list_display = ['name', 'birth_date_view'] @admin.display(empty_value='unknown') def birth_date_view(self, obj): @@ -678,12 +678,12 @@ subclass:: return 1950 <= self.birthday.year < 1960 class PersonAdmin(admin.ModelAdmin): - list_display = ('name', 'born_in_fifties') + list_display = ['name', 'born_in_fifties'] * The ``__str__()`` method is just as valid in ``list_display`` as any other model method, so it's perfectly OK to do this:: - list_display = ('__str__', 'some_other_field') + list_display = ['__str__', 'some_other_field'] * Usually, elements of ``list_display`` that aren't actual database fields can't be used in sorting (because Django does all the sorting @@ -711,7 +711,7 @@ subclass:: ) class PersonAdmin(admin.ModelAdmin): - list_display = ('first_name', 'colored_first_name') + list_display = ['first_name', 'colored_first_name'] The above will tell Django to order by the ``first_name`` field when trying to sort by ``colored_first_name`` in the admin. @@ -731,7 +731,7 @@ subclass:: author = models.ForeignKey(Person, on_delete=models.CASCADE) class BlogAdmin(admin.ModelAdmin): - list_display = ('title', 'author', 'author_first_name') + list_display = ['title', 'author', 'author_first_name'] @admin.display(ordering='author__first_name') def author_first_name(self, obj): @@ -766,7 +766,7 @@ subclass:: return self.first_name + ' ' + self.last_name class PersonAdmin(admin.ModelAdmin): - list_display = ('full_name',) + list_display = ['full_name'] Note that ``@property`` must be above ``@display``. If you're using the old way -- setting the display-related attributes directly rather than @@ -819,13 +819,13 @@ subclass:: linked on the change list page:: class PersonAdmin(admin.ModelAdmin): - list_display = ('first_name', 'last_name', 'birthday') - list_display_links = ('first_name', 'last_name') + list_display = ['first_name', 'last_name', 'birthday'] + list_display_links = ['first_name', 'last_name'] In this example, the change list page grid will have no links:: class AuditEntryAdmin(admin.ModelAdmin): - list_display = ('timestamp', 'message') + list_display = ['timestamp', 'message'] list_display_links = None .. _admin-list-editable: @@ -892,7 +892,7 @@ subclass:: ``select_related`` as parameters. For example:: class ArticleAdmin(admin.ModelAdmin): - list_select_related = ('author', 'category') + list_select_related = ['author', 'category'] will call ``select_related('author', 'category')``. @@ -942,7 +942,7 @@ subclass:: fields it should prepopulate from:: class ArticleAdmin(admin.ModelAdmin): - prepopulated_fields = {"slug": ("title",)} + prepopulated_fields = {"slug": ["title"]} When set, the given fields will use a bit of JavaScript to populate from the fields assigned. The main use for this functionality is to @@ -1045,7 +1045,7 @@ subclass:: ``ManyToManyField``:: class ArticleAdmin(admin.ModelAdmin): - raw_id_fields = ("newspaper",) + raw_id_fields = ["newspaper"] The ``raw_id_fields`` ``Input`` widget should contain a primary key if the field is a ``ForeignKey`` or a comma separated list of values if the field @@ -1081,7 +1081,7 @@ subclass:: from django.utils.safestring import mark_safe class PersonAdmin(admin.ModelAdmin): - readonly_fields = ('address_report',) + readonly_fields = ['address_report'] # description functions like a model field's verbose_name @admin.display(description='Address') @@ -1397,8 +1397,8 @@ templates used by the :class:`ModelAdmin` views: For example, to search by ``name`` and ``age``, you could use:: class PersonAdmin(admin.ModelAdmin): - list_display = ('name', 'age') - search_fields = ('name',) + list_display = ['name', 'age'] + search_fields = ['name'] def get_search_results(self, request, queryset, search_term): queryset, may_have_duplicates = super().get_search_results( @@ -1543,7 +1543,7 @@ templates used by the :class:`ModelAdmin` views: filtering based on add, change, delete, and view permissions:: class MyModelAdmin(admin.ModelAdmin): - inlines = (MyInline,) + inlines = [MyInline] def get_inline_instances(self, request, obj=None): return [inline(self.model, self.admin_site) for inline in self.inlines] @@ -1736,12 +1736,12 @@ templates used by the :class:`ModelAdmin` views: class MyModelAdmin(admin.ModelAdmin): def formfield_for_choice_field(self, db_field, request, **kwargs): if db_field.name == "status": - kwargs['choices'] = ( + kwargs['choices'] = [ ('accepted', 'Accepted'), ('denied', 'Denied'), - ) + ] if request.user.is_superuser: - kwargs['choices'] += (('ready', 'Ready for deployment'),) + kwargs['choices'].append(('ready', 'Ready for deployment')) return super().formfield_for_choice_field(db_field, request, **kwargs) .. admonition:: Note @@ -2063,9 +2063,9 @@ on your ``ModelAdmin``:: class ArticleAdmin(admin.ModelAdmin): class Media: css = { - "all": ("my_styles.css",) + "all": ["my_styles.css"], } - js = ("my_code.js",) + js = ["my_code.js"] The :doc:`staticfiles app </ref/contrib/staticfiles>` prepends :setting:`STATIC_URL` (or :setting:`MEDIA_URL` if :setting:`STATIC_URL` is @@ -2283,7 +2283,7 @@ The ``InlineModelAdmin`` class adds or customizes: class BookInline(admin.TabularInline): model = Book - raw_id_fields = ("pages",) + raw_id_fields = ["pages"] .. attribute:: InlineModelAdmin.template @@ -2451,7 +2451,7 @@ so by defining an ``InlineModelAdmin`` object for the relationship:: inlines = [ MembershipInline, ] - exclude = ('members',) + exclude = ['members'] There are two features worth noting in this example. @@ -2518,10 +2518,10 @@ customized using any of the options available to ``InlineModelAdmin`` classes. Now create admin views for the ``Person`` and ``Group`` models:: class PersonAdmin(admin.ModelAdmin): - inlines = (MembershipInline,) + inlines = [MembershipInline] class GroupAdmin(admin.ModelAdmin): - inlines = (MembershipInline,) + inlines = [MembershipInline] Finally, register your ``Person`` and ``Group`` models with the admin site:: diff --git a/docs/ref/contrib/flatpages.txt b/docs/ref/contrib/flatpages.txt index 35eb4f9bc9..b4e0957fc7 100644 --- a/docs/ref/contrib/flatpages.txt +++ b/docs/ref/contrib/flatpages.txt @@ -185,17 +185,17 @@ registering a custom ``ModelAdmin`` for ``FlatPage``:: # Define a new FlatPageAdmin class FlatPageAdmin(FlatPageAdmin): - fieldsets = ( - (None, {'fields': ('url', 'title', 'content', 'sites')}), + fieldsets = [ + (None, {'fields': ['url', 'title', 'content', 'sites']}), (_('Advanced options'), { - 'classes': ('collapse',), - 'fields': ( + 'classes': ['collapse'], + 'fields': [ 'enable_comments', 'registration_required', 'template_name', - ), + ], }), - ) + ] # Re-register FlatPageAdmin admin.site.unregister(FlatPage) diff --git a/docs/ref/contrib/gis/serializers.txt b/docs/ref/contrib/gis/serializers.txt index f3d465c385..17886412a7 100644 --- a/docs/ref/contrib/gis/serializers.txt +++ b/docs/ref/contrib/gis/serializers.txt @@ -42,7 +42,7 @@ Example:: serialize('geojson', City.objects.all(), geometry_field='point', - fields=('name',)) + fields=['name']) Would output:: diff --git a/docs/ref/contrib/postgres/constraints.txt b/docs/ref/contrib/postgres/constraints.txt index 44f1f56db1..b8a744f2b4 100644 --- a/docs/ref/contrib/postgres/constraints.txt +++ b/docs/ref/contrib/postgres/constraints.txt @@ -248,10 +248,10 @@ current/rangetypes.html#RANGETYPES-INCLUSIVITY>`_. For example:: constraints = [ ExclusionConstraint( name='exclude_overlapping_reservations', - expressions=( + expressions=[ (TsTzRange('start', 'end', RangeBoundary()), RangeOperators.OVERLAPS), ('room', RangeOperators.EQUAL), - ), + ], condition=Q(cancelled=False), ), ] diff --git a/docs/ref/contrib/syndication.txt b/docs/ref/contrib/syndication.txt index 9a65d7bbc2..429565a23c 100644 --- a/docs/ref/contrib/syndication.txt +++ b/docs/ref/contrib/syndication.txt @@ -556,7 +556,7 @@ This example illustrates all possible attributes and methods for a Returns the feed's categories as iterable over strings. """ - categories = ("python", "django") # Hard-coded list of categories. + categories = ["python", "django"] # Hard-coded list of categories. # COPYRIGHT NOTICE -- One of the following three is optional. The # framework looks for them in this order. @@ -604,7 +604,7 @@ This example illustrates all possible attributes and methods for a Returns a list of items to publish in this feed. """ - items = ('Item 1', 'Item 2') # Hard-coded items. + items = ['Item 1', 'Item 2'] # Hard-coded items. # GET_OBJECT -- This is required for feeds that publish different data # for different URL parameters. (See "A complex example" above.) @@ -870,7 +870,7 @@ This example illustrates all possible attributes and methods for a Returns the categories for every item in the feed. """ - item_categories = ("python", "django") # Hard-coded categories. + item_categories = ["python", "django"] # Hard-coded categories. # ITEM COPYRIGHT NOTICE (only applicable to Atom feeds) -- One of the # following three is optional. The framework looks for them in this diff --git a/docs/ref/models/instances.txt b/docs/ref/models/instances.txt index 71fb880740..5ae34b9a77 100644 --- a/docs/ref/models/instances.txt +++ b/docs/ref/models/instances.txt @@ -833,11 +833,11 @@ For example:: from django.db import models class Person(models.Model): - SHIRT_SIZES = ( + SHIRT_SIZES = [ ('S', 'Small'), ('M', 'Medium'), ('L', 'Large'), - ) + ] name = models.CharField(max_length=60) shirt_size = models.CharField(max_length=2, choices=SHIRT_SIZES) |
