Django Level Two Flashcards
what do we use o tie a database to a Django Project?
Models
What backend engine comes with django? is the only one you can use?
SQLite
no
Each attribute of a Model class represents a …
field
SQL operates like a …
giant table
What is a field constraint?
an argument passed into a field method that limits something.
Tables can reference each other using the concepts of ___ and ___.
Foreign Keys and Primary Keys.
__: a unique identifier for each row in a table
Primary Key
___: denotes that the column coincides with a primary key of another table.
Foreign Key
The migrate command:
python manage.py migrate
command to register migrations changes to the app?
python manage.py makemigrations app1
What must we do to interact with models using the admin interface?
We must register them to the app’s admin.py file

A ___ needs to be created to be able to use the Admin features.
superuser
Command for creating a superuser.
python manage.py createsuperuser
The name of the model(class) is synonymous to the name of …
the data-table to be created.
every model (class) inherits from …
the Django base class models.Model
Every attribute aka field, must have its field type specified by …
instantiating it using django’s built in field classes
A constraint of the charfield that limits the amount of characters that can be inserted into the Topic model.
max_length
a kwarg constraint the limits the presence of duplicates.
unique=true
What args get passed into a ForeignKey method?
- The name of the model that it is connected to
- what to do in the case that the associated Model gets deleted.
should you always include a string representation of every model you create?
YES
What package did we learn to use to populate models with fake data? how do we install this package?
Faker
Pip install Faker
List the high level steps for population your website with fake data using Faker.
- configure the project settings to allow for models to be manipulated
- import and set django up
- import all the functions and models needed
- import Faker and instatiate it
- create functions that add data that you generated
- create a function that uses the instatiated Faker object to create however much fake data
- use if __name__ == ‘__main__’ to tell the script when to run

What would be the syntax for creating a fake object using faker?
what does the function .get_or_create() do? what are its args?
.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.
for loop syntax for running an operation N times?
for entry in range(N):
syntax for the if statement tells python to execute the nested instructions if the file is ran directly
if __name__ == ‘__main__’
What are the five points of the MTV paradigm?
- import models into views.py
- extract data from the models using the views functions
- pass the data into the html template
- edit the html template to receive the data and present it to the user appropriately
- Map a URL to the view.
render gets imported from ___.
django.shortcuts
HttpResponse gets imported from ___.
django.http
Models get imported from ___.
app_name.models
What is the syntax for grabbing infor from a model that is ordered by a certain field of the model?
what is the syntax for the HTML equivalent of an if statement?
{% if condition %}
…
{% endif %}
what is the syntax for the HTML equivalent of a for loop?
{% for iteration in iterable %}
…
{% endfor %}
tag heirarchy for tables in html.
- table - table
- thead - head of a table
- th - Item in the table head
- tr - row of a table
- td - item in that row
- thead - head of a table