I created a class base create view.When i try to submite the post model create view. it will return NOT NULL constraint failed: spring_post.publisher_id how can i set the publisher the get the current logged in user and set it to the post piblisher field. im a beginner this is the publisher field in my post model
publisher=models.ForeignKey(User,on_delete=models.PROTECT)
#and this is my views
class PostCreateView(LoginRequiredMixin,CreateView):
model=Post
fields=['title','description']
redirect_field_name="login"
You need to set the
.publisherof the post, so:You probably should also specify the
success_url[Django-doc] to specify where to redirect to if the POST request was successful.