Hello, I create a project for the institute, it consists of a small page with an admin panel and I chose Django to carry out the project.
My problem is that in the page where it shows the details of a career, I want students or registered users to leave a comment, but these comments are not validated.
This is the detail model of a career
This is the model code of the form in question
Class Comment (ITSModel): content = models.TextField () author = models.ForeignKey ( settings.AUTH_USER_MODEL, on_delete = models.CASCADE, related_name = & # 39; comments & # 39; ) carrer = models.ForignKey ( Carrer, related_name = & # 39; comments & # 39; on_delete = models.CASCADE ) def __str __ (auto): return yourself[:23]
This is the code of the form.py
class CommentForm (forms.ModelForm): objective of the class: model = How fields = ['content', 'carrer']
This is the code of the views.py
def create_comment (request):
if request.method == & # 39; POST & # 39 ;:
form = CommentForm (request.POST)
if form.is_valid ():
comment = form.save (commit = False)
comment.author = request.user
return the redirection (comment.carrer.get_absolute_url ())
return HttpResponse ('Something went wrong')