0

I have implemented a ManyToMany relationship that allows duplicate items as in Way to allow for duplicate many-to-many entries in Python/Django. I also have a form, that uses a ModelMultipleChoiceField for this relationship, in order to validate the data that come from an ajax request but after the form is_valid() call, any duplicate items in the ModelMultipleChoiceField are eliminated. Is there any way to keep the duplicate items (I am not interested in the presentation of the form, as I don't use it in a webpage) or do I have to manually go over the request.POST data after the form validation?

Community
  • 1
  • 1
konikos
  • 376
  • 2
  • 9

1 Answers1

0

ModelMultipleChoiceField uses a queryset inside it so every item appears only once (as long as you don't use join's in database queries, but it's unrealted to this question anyway). You can try using simple MultipleChoiceField and construct choices manually duplicating necessary values.

ilvar
  • 5,718
  • 1
  • 20
  • 17
  • I considered using MultipleChoiceField, but I don't know which values are going to be used more than once. Even if I knew those values beforehand, there would have to be more than 5000 choices which doesn't sound like a good idea fetching them from the database each time a request is made. – konikos May 20 '12 at 17:18
  • But you have posted data when you are constructing a form, so you can filter all objects and construct a select with only needed data. Kinda stupid, but it should work :) – ilvar May 21 '12 at 05:04