Django Cards Flashcards

Learn Django syntax

1
Q

Docstring for class Topic

A

”"”A topic the user is learning about”””

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

def __str__(self):

A

Return a string representation of the model

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

Text field data type 50 characters

A
models.CharField(
    max_length=50, 
    blank=False, 
    null=False
)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Text field for data type long

A

models.TextField()

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

Date field with default sysdate

A

models.DateTimeField(auto_now_add=True)

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

Foreigh Key Constraint

A

models.ForeighnKey(Topic, on_delete=models.CASCADE)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
Models Wagtail
class Meta:
A

verbose_name & verbose_name_plural

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

Define url for application

A

app_name = ‘learning_logs’

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

Add learning_logs urls.py to main urls.py

A

path(‘’, include(‘learning_logs.urls’))

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

Add link to topics page (pass topic_id)

A

path(‘topics//’, views.topic, name=’topic’)

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

function to return index.html

A
def index(request):
    """The home page for Learning Log."""
    title = "Home Page"
    context = {'title': title}
    return render(request, 'learning_logs/index.html', context)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

In views.py

import syntax for models and forms

A

from .models import Topic

from .forms import TopicForm, EntryForm

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

Get single row from table Topic

A

Topic.objects.get(id=2)

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

Get topics orderd by name

A

Topic.objects.order_by(‘name’)

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

Syntax in admin.py to register Topic table

A

admin.site.register(Topic)

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

Extend base template

A

{% extends “learning_logs/base.html” %}

17
Q

Main block for html body

A

{% block content %} {% endblock content %}

18
Q

For loop syntax in template html file

A

{% for entry in entries %}

<li><p>{{entry.date_added|date:'m d, Y H:i' }}</p>
<p>{{entry.text}}</p>
</li>

{% empty %}

<li>There are no entries for this topic yet.</li>

{% endfor %}

19
Q

Href with URL tag

A

<a>
Learning Log
</a>