Moving Your Own Common Views in Django

The Django documentation mentions in general class views that a DetailView consists of: View, SingleObjectMixin and SingleObjectTemplateResponseMixin. I am experimenting with this, since I'm interested in creating a general view that will make the object_detail view with ModelForm so that my model strings can be created automatically.

To try to duplicate a DetailView, I tried to create a class as follows:

from django.views.generic import list_detail, View from django.views.generic.detail import (SingleObjectMixin, SingleObjectTemplateResponseMixin, BaseDetailView) class formdisplay(View,SingleObjectMixin,SingleObjectTemplateResponseMixin): pass 

When I use formdisplay instead of list_detail.object_detail, I get an error

 TypeError at /inpatient-detail/4/ __init__() takes exactly 1 non-keyword argument (2 given) 

Any hints on how to do this?

Also, where is the documentation on how to write import statements? I had to search Google to find what to import, since I could not find it in the documentation.

Thanks in advance, Steve

+2
source share
1 answer

Since django's documentation based on a general view of classes is still not very modern, it is best to get more information about them in order to view the source code; to create / update views this is a good start.

When inheriting from multiple classes / mixins, you should also keep track of their order - if you look at the source of django, you will see that they put Mixins in front of other classes!

It is not entirely clear to me what you are trying to achieve, but if your goal is to display a form with data from an existing object, django.views.generic.update.UpdateView should be your friend!

+2
source

Source: https://habr.com/ru/post/891915/


All Articles