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
Quiz details
-
The quiz will be held in class on Tuesday 10/21, 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 what is a primary-key/foreign-key relationship.
-
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 what the Django object manager is. Explain these methods on the object manager:
get,filter, andexclude.
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) published = models.DateTimeField(auto_now=True) image_file = models.ImageField() 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) 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 a method to get all
Comments on anArticle. -
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.