Implementing Model Forms For Blog Project

class createarticleform(forms.ModelForm):
class Meta:
model=models.Article.
fields =(‘title’,‘content’,)

if i use fields=’’“all” i am not able to save articles.

if i use fields =(‘title’,‘content’,) i am able to save articles but cannot set author from the form page.

how to display and select the “author”(many to many field in Article model) when creating a article in the model form

Hello @anuj785pandey, if you want to select the authors then you need to define that in the forms.
Like

authors = forms.ModelMultipleChoiceField(queryset=Authors.objects.all())

For more details pls have a look at this…


If you have any issue pls let me know.

the authors (html heading ) is visible now but still the problems remains the same .
however when I do inspect element my author list is visible to me on the inspect section inside the select tags

Hey it got resolved . ( actually materialize.css need a Javascript component to be included in order to have the select tag working )

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.