CS412
Spring 2026

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:

Quiz details

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.

  1. Explain the difference between a using a URLField to refer to an image and an ImageField. What are the consequences for referring to the image within the img tag?

  2. Identify and explain the 2 roles and responses of the UpdateView, with respect to the GET/POST methods.

  3. Explain why it is necessary to implement the get_success_url method on a subclass of the generic DeleteView.

  4. Explain, giving an example, the role of the get_absolute_url method on a model class.

  5. Explain what the Django object manager is. Explain these methods on the object manager: get, filter, and exclude.

  6. Identify and explain the main components of the Django buit-in authentication model, including class django.auth.User.

  7. The built-in LoginView and LogoutView are used in Django to handle user authentication. Explain how you would integrate them into a web application to use these features.

  8. Explain what the LoginRequiredMixin class does, and how we use it in our applications.

  9. Explain how you created a new User in the mini_insta assignment. 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'), 
]
  1. Write the HTML source code to display the image as part of an Article.

  2. Write a subclass of UpdateView to update a Comment. Write the URL pattern for this view.

  3. Write the code to retrieve all Comments on all Articles published by 'John Lennon', where the Comments were published after 2025-06-05.

  4. Write a subclass of CreateView to create a new Comment, requiring that the user be logged in. Store the FK of the Django User with the Comment.