2👍
✅
I would recommend overwriting the save()
method and passing the user to it like this:
class NewsForm(ModelForm):
def save(self, author, commit=True):
# Don't commit the results yet
news = ModelForm.save(self, commit=False)
news.author = author
if commit:
news.save()
return news
class Meta:
model = News
exclude = ('pub_date','author',)
Source:stackexchange.com