Introduction to CBVs Flashcards
Code for adding class-based views to your apps urls.py file?
code for calling nothing but a template using class based views.
explain what **kwargs and *args means.
prepares a function to accept an arbitrary number of args of kwargs.
Code for injecting content into a cbv.
what model field class is for the input of positive whole numbers
PositiveIntegerField()
In a class based view, what line of code provides you with a list of all the information contained in a model?
model = models.School
line of code for assigning a template to a cbv.
template_name = ‘basic_app/school_detail.html’
how do you change the context object name in the view function?
context_object_name = ‘schools’
ListView returns …
DetailView returns …
model_name_list
model_name
An example of a line of code that relates a list of objects to a ForeignKey
path() function in urls.py that links a view to an the id of a model.
how do you reference a specific instance of a model’s cbv as a link
What does CRUD stand for?
- Create
- Retreat
- Update
- Delete
url pattern for the CreateView cbv.
for the CreateView cbv, what template name does django automatically look for?
the name of the model being created underscore form.html
model_form.html
explain this block of html code?
{% if not form.instance.pk %}
Create School
{% else %}
Update School
{% endif %}
- check if the instance of the primary key exists or not
- if it does not print “Create School”
- else print “Update School”
what goes into the get_absolute_url() method?
14 - go to the detail view of the school you just made
14 - using the pk of the school you just created.
| , kwargs={‘pk’:self.pk}) |
(reverse(“basic_app:detail” |
what attributes need to be defined in the SchoolCreateView?
What does success_url = reverse_lazy(“basic_app:list”) do?
- what to do upon successful deletion
- dont execute this code immediately, only when the deletion of the object has been confirmed.
When does the get_absolute_url() method need to be present in a models code?
when you have a view that uses the CreateView class, django needs to know where to take the user upon creating that new model.