I have two models - News and Subject. News model has a ManyToManyField related to Subject, like that:
subjects = models.ManyToManyField(NewsSubject, verbose_name=u'Subjects', blank=True,null=True,related_name='news')
And I need to have an ability not only to choose Subjects for News in admin, but also to choose News while editing Subject.
I'd started from creating model form:
class NewsSubjectForm(forms.ModelForm):
news = ModelMultipleChoiceField(queryset=News.objects.all(),
label="News",
required=False,
#initial=News.objects.all(),
)
class Meta:
model = NewsSubject
Here is the question - how I should specify initial values for news according to reverse many-to-many relationship? And how to add a plus button for simple adding?