Creating a review
We have seen how to create model objects from the admin – for example, creating a movie
object. But how do we allow users to create their own objects, such as letting them post a review from the site? After all, not everyone should have access to the admin panel.
Let's create a page for them to do so:
- We first create a path in
/movie/urls.py
:from django.urls import path from . import views urlpatterns = [ path('<int:movie_id>', views.detail, name='detail'), path('<int:movie_id>/create', views.createreview, name='createreview'), ]
/movie/views.py
- In
/movie/views.py
, adddef createreview
:… from django.shortcuts import get_object_or_404, redirect from .models import Movie, Review from .forms...