Quiz 3 Information
Material covered
The quiz will focus on the material that we have discussed in class, with an emphasis on material covered during this part of the course. These topics include:
- Storage and retrieval of images using the
ImageField - Performing update and delete operations
- Using the Django Object Manager class and methods
- Authentication and user accounts
Quiz details
-
The quiz will be held in class on Tuesday 3/17, beginning promptly at the start of class. You will have 30 minutes to complete the quiz. The remaining time after the quiz will be workshop time to work on assignment 7.
-
The quiz will be a paper quiz, in which you will hand-write your responses. Each question will be a short-answer format; you should write complete sentences (not bullet points), approximate 4-5 sentences about about 75-100 words per response.
-
The quiz will be closed notes/closed books. You may not use any PowerPoint slides, examples, assignments, webpages, or other electronic devices/resources during the quiz.
Sample Questions
The following sample questions are provided to give you an idea about how the questions will be posed, but this is NOT a complete or sufficient study guide.
-
Explain the difference between a using a
URLFieldto refer to an image and anImageField. What are the consequences for referring to the image within theimgtag? -
Identify and explain the 2 roles and responses of the
UpdateView, with respect to the GET/POST methods. -
Explain why it is necessary to implement the
get_success_urlmethod on a subclass of the genericDeleteView. -
Explain, giving an example, the role of the
get_absolute_urlmethod on a model class. -
Explain what the Django object manager is. Explain these methods on the object manager:
get,filter, andexclude. -
Identify and explain the main components of the Django buit-in authentication model, including class
django.auth.User. -
The built-in
LoginViewandLogoutVieware used in Django to handle user authentication. Explain how you would integrate them into a web application to use these features. -
Explain what the
LoginRequiredMixinclass does, and how we use it in our applications. -
Explain how you created a new
Userin themini_instaassignment. Be specific about forms, views, URLS, and any custom code you had to write (i.e., what did you need to do).
Sample Programming Questions
Given this model definition:
class Article(models.Model): '''Encapsulate the idea of an Article by some author.''' # data attributes of a Article: title = models.TextField(blank=False) author = models.TextField(blank=False) text = models.TextField(blank=False) image_file = models.ImageField() user = models.ForeignKey(User, on_delete=models.CASCADE) published = models.DateTimeField(auto_now=True) def __str__(self): '''Return a string representation of this Article object.''' return f'{self.title} by {self.author}' class Comment(models.Model): '''Encapsulate the idea of a Comment on an Article.''' # data attributes of a Comment: article = models.ForeignKey("Article", on_delete=models.CASCADE) author = models.TextField(blank=False) text = models.TextField(blank=False) user = models.ForeignKey(User, on_delete=models.CASCADE) published = models.DateTimeField(auto_now=True) def __str__(self): '''Return a string representation of this Comment object.''' return f'{self.text}'
This view definition:
class ShowAllView(ListView): '''Create a subclass of ListView to display all blog articles.''' model = Article # retrieve objects of type Article from the database template_name = 'blog/show_all.html' context_object_name = 'articles' # how to find the data in the template file
And this URL pattern defintion:
urlpatterns = [
path('', ShowAllView.as_view(), name='show_all'),
]
-
Write the HTML source code to display the image as part of an
Article. -
Write a subclass of
UpdateViewto update aComment. Write the URL pattern for this view. -
Write the code to retrieve all
Commentson allArticlespublished by'John Lennon', where theComments were published after2025-06-05. -
Write a subclass of
CreateViewto create a newComment, requiring that the user be logged in. Store the FK of the DjangoUserwith theComment.