Django show manytomanyfield on form when definition is on other model

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2010-04-21T15:11:00Z Indexed on 2010/04/22 9:23 UTC
Read the original article Hit count: 249

Filed under:
|

Hi

I have the definition for my manytomany relationship on one model but want to display the field on a form for the other model. How do I do this?

for example:

# classes
class modelA(models.Model):
   name = models.CharField(max_length=300)
   manytomany = models.ManyToManyField(modelA)

class modelB(models.Model):
   name = models.CharField(max_length=300)

# forms
class modelBForm(forms.ModelForm):
    class Meta:
        model = modelB

I want to use the form modelBForm but show a select box with a list from modelA (just how it would work if the model was set to modelA in the form class). How can I do this?

Thanks

© Stack Overflow or respective owner

Related posts about django

Related posts about django-forms