У меня есть два универсальных c представления ( CreateView и DetailView ).
В моем CreateView после сохранения формы я хочу перенаправить на DetailView для отображения Мой недавно созданный объект.
Но произошла ошибка: Reverse for 'questions.views.DisplayQuestions' not found. 'questions.views.DisplayQuestions' is not a valid view function or pattern name.
Как я могу вызвать мой DetailView с reverse_lazy
?
.views :
class DisplayQuestions(ListView):
model = Question
context_object_name = "all_questions"
template_name = "questions/home.html"
def get_queryset(self):
return Question.objects.order_by(self.kwargs['display_type'])
@method_decorator(login_required, name='dispatch')
class CreateQuestion(CreateView):
model = Question
template_name = 'questions/nouveau.html'
form_class = QuestionForm
def get_success_url(self):
return reverse_lazy(DisplayQuestion) # <-- This doesn't work !!!
def form_valid(self, form):
self.object = form.save(commit=False)
self.object.profil = self.request.user.profil
self.object = form.save()
return HttpResponseRedirect(self.get_success_url())
.urls:
urlpatterns = [
url(r'^nouveau$', views.CreateQuestion.as_view()),
url(r'(?P<display_type>\w+)', views.DisplayQuestions.as_view()),]
.forms:
class QuestionForm(forms.ModelForm):
class Meta:
model = Question
fields = ('question','categorie',)