Django display manytomany field in 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 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