I have a model:
class Article(models.Model):
text = models.CharField()
author = models.ForeignKey(User)
How do I write class-based view that creates a new model instance and sets author foreign key to request.user?
Update:
Solution moved to separate answer below.
I solved this by overriding
form_validmethod. Here is verbose style to clarify things:Yet we can make it short (thanks dowjones123), this case is mentioned in docs.: