2

How would one even start to implement something like this with a django form:

CHOICES = (
    ('a','a',forms.IntegerField()),
    ('b','b',forms.IntegerField()
)
class AForm(forms.Form):
    choice = forms.CharField(choices=CHOICES)

Bit of background: I am trying to convert a ModelMultipleChoiceField into a custom formField that displays the model and an additional input per object (that is used to select basically quantity)

So i need to somehow insert a field into the choices tuple (obs that won't work so where would i even start to re-write the ChoiceField to take an extra parameter)

Trying to go through the source of ChoiceField https://docs.djangoproject.com/en/1.11/ref/forms/fields/#choicefield but I can't work out where I even begin to add the new field (and retrieve it after POST!)

joeskru
  • 242
  • 3
  • 16
  • 1
    You should strongly consider a [Formset](https://docs.djangoproject.com/en/1.11/topics/forms/formsets/). – user2390182 May 09 '17 at 15:31
  • @joeskru what you want is really complex, are you sure this is the right way to go? There are less complex solutions to that problem. – John Moutafis May 10 '17 at 09:38
  • @johnMouyafis yeh i realise this is not really a viable solution, just using the example as pseudo code. As schwobaseggl suggested I'm looking into a formset but still not sure i can even achieve an outcome that way. – joeskru May 10 '17 at 09:51
  • Easily achieved with a formset, mainly used this post for reference as the django docs feel a bit lacking (which is rare!) http://whoisnicoleharris.com/2015/01/06/implementing-django-formsets.html – joeskru May 11 '17 at 11:06

0 Answers0