An authorized user leaves a comment on the page. How do I implement the got_comment(request) view got_comment(request) There is a model:

 class Comment(models.Model): comment_nickname = models.ForeignKey(Stranger, on_delete=models.CASCADE, related_name='+') comment_text = models.CharField(max_length=1000) 

The key to the user authentication session is request.session ['stranger_id']. I thought to implement something like this:

 def got_comment(request): c = Comment(comment_text=request.POST['comment_text'], comment_nickname="""""") 

But I do not know what to write at the end of the line.

  • Are you trying to save a comment to the database? - Sergey Gornostaev
  • Yes, I'm trying to save to the base. An instance of the model is also created in the view. - Anton

1 answer 1

 def got_comment(request): c = Comment(comment_text=request.POST['comment_text'], comment_nickname=Stranger.objects.get(id = request.session['stranger_id'])) c.save() 
  • id is a Python built-in function - Anton