Opened 7 years ago

Closed 7 years ago

#28624 closed New feature (wontfix)

Add attribute to let a ManyToMany field behave like a list instead of a set

Reported by: david simmen Owned by: david simmen
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

An attribute which surpresses the uniw constraint creation an the generated join table

Change History (4)

comment:1 by Simon Charette, 7 years ago

Hello David, what's the purpose of disabling this constraint?

Isn't something you can achieve by defining a through model without a unique_together constraint? I'm not convinced this is a scenario common enough to warrant yet another option to ManyToManyField.

comment:2 by Tim Graham, 7 years ago

Resolution: wontfix
Status: assignedclosed

I agree with Simon's assessment.

comment:3 by david simmen, 7 years ago

Resolution: wontfix
Status: closednew

So I went along and used the through functionality for this and run into the following issues

  • i had to add a model calss with just two foreing keys which clutters up my code
  • I lost all the add create functionality which also makes the code more complex and less understandable

so from an architectural point ov view it would be way more beautiful to have a parameter on the field

also I do not understand why it is a set by default since I could not find a definition for many to many which says it has to be a set, so why use a more limiting collection?

and last but not least i think there are many usecases where a many to many is a list for example with order and products where a product can be many times in the same order, and that is not an out of the world scenario

comment:4 by Tim Graham, 7 years ago

Resolution: wontfix
Status: newclosed

A list isn't appropriate because the database wouldn't preserve ordering of many-to-many relations.

Maybe django-sortedm2m would be appropriate for your use case.

To revisit a "wontfix" decision, see TicketClosingReasons/DontReopenTickets.

By the way, the add(), create(), etc. limitation of using a through model will be lifted when #9475 is completed.

Note: See TracTickets for help on using tickets.
Back to Top