Models.py:
class Comment(models.Model):
user = models.ForeignKey(User)
document = models.ForeignKey(Document)
section = models.ForeignKey(Section, null=True, blank=True)
description = models.TextField(null=True, blank=True)
Forms.py:
class CommentForm(ModelForm):
class Meta:
model = Comment
fields = ('section', 'description')
Each Comment belongs to a Section of a Document. Each Document hasmany Sections. However, the ModelChoiceField printed out by Django will contain Sections for ALL Documents.
How do I tell Django to only print the Sections that belong to a particular Document?
I looked at ModelFormSets – Changing the queryset but I don’t think it’s quite what I’m after.
I think you want to change the ModelChoiceField’s queryset and not the queryset of the formset.