Opened 6 years ago
Closed 5 years ago
#30421 closed New feature (fixed)
Allow ManyToManyField using a intermediary table to be defined as symmetrical.
Reported by: | Nadege | Owned by: | Nadege |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | many2many, through, symmetrical, through |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Thanks to the work made by Collin Anderson in #9475 I think we can remove the check
"fields.E332 Many-to-many fields with intermediate tables must not be symmetrical." with a little adjustment.
This change was discussed in the django-dev mailing list https://groups.google.com/forum/#!topic/django-developers/BuT0-Uq8pyc.
This would let have
class Person(models.Model): name = models.CharField(max_length=20) friends = models.ManyToManyField('self', through='Friendship') class Friendship(models.Model): first = models.ForeignKey(Person, models.CASCADE, related_name="+") second = models.ForeignKey(Person, models.CASCADE) friendship_date = models.DateTimeField()
and just do something like
joe.friends.add(anna, through_defaults={'friendship_date': date.datetime(...)})
where currently we would have to do
joe.friends.add(anna, through_defaults={'friendship_date': date.datetime(...)}) anna.friends.add(joe, through_defaults={'friendship_date': date.datetime(...)})
Change History (6)
comment:1 by , 6 years ago
Has patch: | set |
---|
comment:2 by , 6 years ago
comment:3 by , 6 years ago
Summary: | Allow ManyToMany using a intermediary table to be defined as symmetrical → Allow ManyToManyField using a intermediary table to be defined as symmetrical. |
---|---|
Triage Stage: | Unreviewed → Accepted |
Version: | 2.2 → master |
comment:4 by , 5 years ago
Patch needs improvement: | set |
---|
comment:5 by , 5 years ago
Patch needs improvement: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
Note:
See TracTickets
for help on using tickets.
Pull request: https://github.com/django/django/pull/11298