Django Level Two Flashcards

1
Q

what do we use o tie a database to a Django Project?

A

Models

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

What backend engine comes with django? is the only one you can use?

A

SQLite

no

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

Each attribute of a Model class represents a …

A

field

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

SQL operates like a …

A

giant table

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

What is a field constraint?

A

an argument passed into a field method that limits something.

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

Tables can reference each other using the concepts of ___ and ___.

A

Foreign Keys and Primary Keys.

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

__: a unique identifier for each row in a table

A

Primary Key

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

___: denotes that the column coincides with a primary key of another table.

A

Foreign Key

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

The migrate command:

A

python manage.py migrate

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

command to register migrations changes to the app?

A

python manage.py makemigrations app1

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

What must we do to interact with models using the admin interface?

A

We must register them to the app’s admin.py file

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

A ___ needs to be created to be able to use the Admin features.

A

superuser

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

Command for creating a superuser.

A

python manage.py createsuperuser

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

The name of the model(class) is synonymous to the name of …

A

the data-table to be created.

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

every model (class) inherits from …

A

the Django base class models.Model

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

Every attribute aka field, must have its field type specified by …

A

instantiating it using django’s built in field classes

17
Q

A constraint of the charfield that limits the amount of characters that can be inserted into the Topic model.

A

max_length

18
Q

a kwarg constraint the limits the presence of duplicates.

A

unique=true

19
Q

What args get passed into a ForeignKey method?

A
  1. The name of the model that it is connected to
  2. what to do in the case that the associated Model gets deleted.
20
Q

should you always include a string representation of every model you create?

A

YES

21
Q

What package did we learn to use to populate models with fake data? how do we install this package?

A

Faker

Pip install Faker

22
Q

List the high level steps for population your website with fake data using Faker.

A
  1. configure the project settings to allow for models to be manipulated
  2. import and set django up
  3. import all the functions and models needed
  4. import Faker and instatiate it
  5. create functions that add data that you generated
  6. create a function that uses the instatiated Faker object to create however much fake data
  7. use if __name__ == ‘__main__’ to tell the script when to run
23
Q

What would be the syntax for creating a fake object using faker?

A
24
Q

what does the function .get_or_create() do? what are its args?

A

.get_or_create() will retrieve the field if it already exists in the model, and if not it will create it.

it is composed of an arbitrary number of kwargs, matching the models field object with the instance of fake data that was generated for that field.

25
Q

for loop syntax for running an operation N times?

A

for entry in range(N):

26
Q

syntax for the if statement tells python to execute the nested instructions if the file is ran directly

A

if __name__ == ‘__main__’

27
Q

What are the five points of the MTV paradigm?

A
  1. import models into views.py
  2. extract data from the models using the views functions
  3. pass the data into the html template
  4. edit the html template to receive the data and present it to the user appropriately
  5. Map a URL to the view.
28
Q

render gets imported from ___.

A

django.shortcuts

29
Q

HttpResponse gets imported from ___.

A

django.http

30
Q

Models get imported from ___.

A

app_name.models

31
Q

What is the syntax for grabbing infor from a model that is ordered by a certain field of the model?

A
32
Q

what is the syntax for the HTML equivalent of an if statement?

A

{% if condition %}

{% endif %}

33
Q

what is the syntax for the HTML equivalent of a for loop?

A

{% for iteration in iterable %}

{% endfor %}

34
Q

tag heirarchy for tables in html.

A
  • table - table
    • thead - head of a table
      • th - Item in the table head
    • tr - row of a table
      • td - item in that row