First Clone Project Flashcards
what should you do if you ever get this error:
“No module module_name”
install the module:
pip install module_name
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?
models.py
what does the second arg in this DateTimeField mean? (Post, models.py)
date_published = models.DateTimeField(blank=True,null=True)
a post doesnt need to have a date_publised attribute.
explain the arg: (Post, models.py)
date_created = models.DateTimeField(default=timezone.now())
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
explain the arg: (Post, models.py)
author = models.ForeignKey(‘auth.User’)
this is linking the author to the authorized user, so that only they can make blog posts.
what is the purpose of this method?: (Post, models.py)
def publish(self):
self. published_date = timezone.now()
self. save()
- 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.
what is this code doing? (Post, models.py)
def approve\_comments(self): return self.comments.filter(approved\_comment=True)
returns a list of comments that were approved so that they can be shown along with the blog post.
what does this line of code mean in a nutshell: (Comment model)
post = models.ForeignKey(‘blog.Post’, related_name=’comments’,
on_delete=models.CASCADE)
each comment will be connected a post, when that post gets deleted, so to do the comments.
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’})
}
preassigning to the form fields classes that are already made or will be made in css.
where does the widget attribute go in a Form Class?
under the class Meta()
Why does it make sense for each individual application to have its own static and template folder?
- keeps everything modular
- makes it easier to use stuff across apps and projects
what is the reason for the dash before published_date.
.order_by(‘-published_date’))
Makes the order newest, to oldest.
explain this line of code:
Post.objects.filter(published_date__lte=timezone.now().order_by(‘-published_date’))
- 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
what is the class based views version of the decorators like login_required?
where is it imported from?
what do you do with it?
LoginRequiredMixin
django.contrib.auth.mixins
pass it into the class based view as an arg
what fields need to be added to a class based view that inherits from LoginRequiredMixin?
- *login_url** = ‘/login/’
- *redirect_field_name** = ‘blog/post_detail.html’