Opened 5 years ago
Closed 2 years ago
#30947 closed Cleanup/optimization (fixed)
Apply data structure best practices to the django.contrib models and docs
Reported by: | Jon Dufresne | Owned by: | Alex Morega |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Johannes Maron | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
In PR https://github.com/django/django/pull/11267 an argument is presented that explains why list
is often the best choice for Model.Meta data structures. This landed as https://github.com/django/django/commit/97d3321e89c8d4434927bdbc308db1ccffa99d3b.
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.
Change History (22)
comment:1 by , 5 years ago
Cc: | added |
---|---|
Component: | Uncategorized → Documentation |
Has patch: | set |
Owner: | changed from | to
Status: | new → assigned |
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 5 years ago
Patch needs improvement: | set |
---|
comment:3 by , 5 years ago
Patch needs improvement: | unset |
---|
comment:9 by , 4 years ago
Summary: | Apply data structure best practices to the django.contrib models → Apply data structure best practices to the django.contrib models and docs |
---|
#30947 was a duplicate for extra docs changes.
comment:10 by , 4 years ago
Has patch: | unset |
---|---|
Resolution: | fixed |
Status: | closed → new |
Triage Stage: | Ready for checkin → Accepted |
comment:11 by , 2 years ago
Owner: | removed |
---|---|
Status: | new → assigned |
comment:12 by , 2 years ago
Status: | assigned → new |
---|
comment:13 by , 2 years ago
Easy pickings: | set |
---|
comment:16 by , 2 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
Ok so I have to convert tuple of list to list of list.
comment:17 by , 2 years ago
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
comment:18 by , 2 years ago
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.
comment:19 by , 2 years ago
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 asset
and notlist
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 order of columns matters.
There hasn't been any activity on the ticket for 3 weeks; may I take ownership?
comment:20 by , 2 years ago
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')}
.
comment:22 by , 2 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:24 by , 2 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Updated PR.