Introduction to CBVs Flashcards

1
Q

Code for adding class-based views to your apps urls.py file?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

code for calling nothing but a template using class based views.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

explain what **kwargs and *args means.

A

prepares a function to accept an arbitrary number of args of kwargs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Code for injecting content into a cbv.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what model field class is for the input of positive whole numbers

A

PositiveIntegerField()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

In a class based view, what line of code provides you with a list of all the information contained in a model?

A

model = models.School

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

line of code for assigning a template to a cbv.

A

template_name = ‘basic_app/school_detail.html’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

how do you change the context object name in the view function?

A

context_object_name = ‘schools’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

ListView returns …

DetailView returns …

A

model_name_list

model_name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

An example of a line of code that relates a list of objects to a ForeignKey

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

path() function in urls.py that links a view to an the id of a model.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

how do you reference a specific instance of a model’s cbv as a link

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does CRUD stand for?

A
  • Create
  • Retreat
  • Update
  • Delete
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

url pattern for the CreateView cbv.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

for the CreateView cbv, what template name does django automatically look for?

A

the name of the model being created underscore form.html

model_form.html

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

explain this block of html code?

{% if not form.instance.pk %}
Create School
{% else %}
Update School
{% endif %}

A
  • check if the instance of the primary key exists or not
    • if it does not print “Create School”
    • else print “Update School”
17
Q

what goes into the get_absolute_url() method?

A

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” |

18
Q

what attributes need to be defined in the SchoolCreateView?

A
19
Q

What does success_url = reverse_lazy(“basic_app:list”) do?

A
  • what to do upon successful deletion
  • dont execute this code immediately, only when the deletion of the object has been confirmed.
20
Q

When does the get_absolute_url() method need to be present in a models code?

A

when you have a view that uses the CreateView class, django needs to know where to take the user upon creating that new model.