Now change all models in `django.contrib` to follow our own stated best
practices. People often look at existing examples for how to write new
code, so we might as well promote the standards we document.
--
Ticket URL: <https://code.djangoproject.com/ticket/30947>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => assigned
* cc: Johannes Hoppe (added)
* component: Uncategorized => Documentation
* owner: nobody => Jon Dufresne
* has_patch: 0 => 1
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/30947#comment:1>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/30947#comment:2>
* needs_better_patch: 1 => 0
Comment:
Updated PR.
--
Ticket URL: <https://code.djangoproject.com/ticket/30947#comment:3>
* stage: Accepted => Ready for checkin
Comment:
It`s ok.
--
Ticket URL: <https://code.djangoproject.com/ticket/30947#comment:4>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"b9fe7f9294b1b4fc974c008adeb96e1375cdb0c6" b9fe7f92]:
{{{
#!CommitTicketReference repository=""
revision="b9fe7f9294b1b4fc974c008adeb96e1375cdb0c6"
Fixed #30947 -- Changed tuples to lists in model Meta options in
django.contrib modules.
The Django "Model Meta options" docs provide examples and generally
point the reader to use lists for the unique_together and ordering
options. Follow our own advice for contrib models.
More generally, lists should be used for homogeneous sequences of
arbitrary lengths of which both unique_together and ordering are.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30947#comment:6>
Comment (by Jon Dufresne <jon.dufresne@…>):
In [changeset:"e5cacb1f47cb3a2943bbc7685a630c84503b0d1b" e5cacb1]:
{{{
#!CommitTicketReference repository=""
revision="e5cacb1f47cb3a2943bbc7685a630c84503b0d1b"
Refs #30947 -- Changed tuples to lists in model Meta options examples in
docs.
Follow up to 97d3321e89c8d4434927bdbc308db1ccffa99d3b.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30947#comment:5>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"2000ed5180308ae844f3df7e4ed1be64e163755b" 2000ed51]:
{{{
#!CommitTicketReference repository=""
revision="2000ed5180308ae844f3df7e4ed1be64e163755b"
[3.0.x] Refs #30947 -- Changed tuples to lists in model Meta options
examples in docs.
Follow up to 97d3321e89c8d4434927bdbc308db1ccffa99d3b.
Backport of e5cacb1f47cb3a2943bbc7685a630c84503b0d1b from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30947#comment:7>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"a7f90d9c02f5ed6f6dc1621ef10b9db1f042600b" a7f90d9]:
{{{
#!CommitTicketReference repository=""
revision="a7f90d9c02f5ed6f6dc1621ef10b9db1f042600b"
[2.2.x] Refs #30947 -- Changed tuples to lists in model Meta options
examples in docs.
Follow up to 97d3321e89c8d4434927bdbc308db1ccffa99d3b.
Backport of e5cacb1f47cb3a2943bbc7685a630c84503b0d1b from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30947#comment:8>
Comment (by Mariusz Felisiak):
#30947 was a duplicate for extra docs changes.
--
Ticket URL: <https://code.djangoproject.com/ticket/30947#comment:9>
* status: closed => new
* has_patch: 1 => 0
* resolution: fixed =>
* stage: Ready for checkin => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/30947#comment:10>
* owner: Jon Dufresne => (none)
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/30947#comment:11>
* status: assigned => new
--
Ticket URL: <https://code.djangoproject.com/ticket/30947#comment:12>
* easy: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/30947#comment:13>
* owner: (none) => rihib
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/30947#comment:14>
* owner: rihib => (none)
* status: assigned => new
--
Ticket URL: <https://code.djangoproject.com/ticket/30947#comment:15>
* owner: (none) => Ojas Gupta
* status: new => assigned
Comment:
Ok so I have to convert tuple of list to list of list.
--
Ticket URL: <https://code.djangoproject.com/ticket/30947#comment:16>
Comment (by Alex Morega):
This is actually a pet peeve of mine; would love to see the docs updated
to using lists instead of tuples.
Would this be a good checklist of places to update in the codebase and
docs? https://gist.github.com/mgax/32318118a71ce602a00a80daeecb60fc
--
Ticket URL: <https://code.djangoproject.com/ticket/30947#comment:17>
Comment (by Simon Charette):
Some of the examples you pointed should remain tuples as they are mixing
heterogenous data and mostly used to a define a schema over data.
Since we're on the topic of data structure best practices
`unique_together` and friends should likely be defined as `set` and not
`list` as only unique entries will be considered and because the order in
which they are defined on the model doesn't have any significance.
--
Ticket URL: <https://code.djangoproject.com/ticket/30947#comment:18>
Comment (by Alex Morega):
> Some of the examples you pointed should remain tuples as they are mixing
heterogenous data and mostly used to a define a schema over data.
Right! I meant it as a starting point of places that might need fixing.
> Since we're on the topic of data structure best practices
`unique_together` and friends should likely be defined as `set` and not
`list` as only unique entries will be considered and because the order in
which they are defined on the model doesn't have any significance.
I see your point, but AFAIU, a side effect of `unique_together` is
creating composite database indexes, where the
[https://www.postgresql.org/docs/current/indexes-multicolumn.html order of
columns matters].
There hasn't been any activity on the ticket for 3 weeks; may I take
ownership?
--
Ticket URL: <https://code.djangoproject.com/ticket/30947#comment:19>
Comment (by Simon Charette):
> I see your point, but AFAIU, a side effect of unique_together is
creating composite database indexes, where the order of columns matters.
The order of columns within an index or unique constraints matter, but the
order of constraints doesn't. This obviously means that you can't use the
''flattened'' syntax `index_together = {'foo', 'bar'}` but favor
`index_together = {('foo', 'bar')}`.
--
Ticket URL: <https://code.djangoproject.com/ticket/30947#comment:20>
* owner: Ojas Gupta => Alex Morega
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/16003 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/30947#comment:21>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/30947#comment:22>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"de6c9c70549010fc39509f9ef3f6a62ada870318" de6c9c7]:
{{{
#!CommitTicketReference repository=""
revision="de6c9c70549010fc39509f9ef3f6a62ada870318"
Refs #30947 -- Changed tuples to lists where appropriate.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30947#comment:23>
* status: assigned => closed
* resolution: => fixed
--
Ticket URL: <https://code.djangoproject.com/ticket/30947#comment:24>