First Clone Project Flashcards

1
Q

what should you do if you ever get this error:

“No module module_name”

A

install the module:

pip install module_name

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

what .py file does Jose suggest starting on after creating the project, the app, and the urls.py and forms.py file for the app?

A

models.py

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

what does the second arg in this DateTimeField mean? (Post, models.py)

date_published = models.DateTimeField(blank=True,null=True)

A

a post doesnt need to have a date_publised attribute.

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

explain the arg: (Post, models.py)

date_created = models.DateTimeField(default=timezone.now())

A

the date_created attribute will be set to be the time at the moment the block is created, based on the timezone settings in settings.py

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

explain the arg: (Post, models.py)

author = models.ForeignKey(‘auth.User’)

A

this is linking the author to the authorized user, so that only they can make blog posts.

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

what is the purpose of this method?: (Post, models.py)

def publish(self):

self. published_date = timezone.now()
self. save()

A
  • preparing the functionality of a publish button that will be made.
  • when that button is hit, the method will be called and will set the published_date attribute to the current time.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what is this code doing? (Post, models.py)

def approve\_comments(self):
 return self.comments.filter(approved\_comment=True)
A

returns a list of comments that were approved so that they can be shown along with the blog post.

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

what does this line of code mean in a nutshell: (Comment model)

post = models.ForeignKey(‘blog.Post’, related_name=’comments’,
on_delete=models.CASCADE)

A

each comment will be connected a post, when that post gets deleted, so to do the comments.

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

what is this doing in a nutshell?: (forms.py)

widgets = {
‘title’:forms.TextInput(attrs={‘class’:’textinputclass’}),
‘text’:forms.Textarea(attrs={‘class’:’editable medium-editor-textarea postcontent’})
}

A

preassigning to the form fields classes that are already made or will be made in css.

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

where does the widget attribute go in a Form Class?

A

under the class Meta()

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

Why does it make sense for each individual application to have its own static and template folder?

A
  • keeps everything modular
  • makes it easier to use stuff across apps and projects
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

what is the reason for the dash before published_date.

.order_by(‘-published_date’))

A

Makes the order newest, to oldest.

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

explain this line of code:

Post.objects.filter(published_date__lte=timezone.now().order_by(‘-published_date’))

A
  • get all objects from the Post model that has a published that is less than or equal to the current time
  • order those objects by published date in descending order
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

what is the class based views version of the decorators like login_required?

where is it imported from?

what do you do with it?

A

LoginRequiredMixin

django.contrib.auth.mixins

pass it into the class based view as an arg

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

what fields need to be added to a class based view that inherits from LoginRequiredMixin?

A
  • *login_url** = ‘/login/’
  • *redirect_field_name** = ‘blog/post_detail.html’
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

get_queryset function code for return a list of all the blog posts that are drafts (null=true)

A
def get\_queryset(self):
 return Post.objects.filter(published\_date\_\_isnull=True).order\_by('created\_date')
17
Q

what is the point of assigning comment.post.pk to a variable?

post_pk = comment.post.pk
comment.delete()
redirect(‘post_detail’,pk=post_pk)

A

because we are about to delete the comment. so we wouldnt be able to use comment.post.pk in the redirect method.

18
Q

what is the purpose of the kwargs?

path(‘accounts/login/’,views.LogoutView ,name=’logout’,kwargs={‘next_page’:’/’}),

A

sends the user back to the homepage after logging out.

19
Q

how does the browser know where to go when after logging in?

A

add this under the submit button input tag

<input></input>