Django display manytomany field in 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/21 15:13 UTC
Read the original article Hit count: 242

Filed under:
|

Hi

I have the definition for my manytomany relationship on one model but want to display the field on the form of my 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

If I then used modelBForm it would show a select box with the models from modelA rather than just name.

Thanks

© Stack Overflow or respective owner

Related posts about django

Related posts about django-forms