Django show manytomanyfield on form when definition is on other model
- by John
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