9.2.3 Creating Post Objects in a View with PostForm

Let’s use our view for creating Post objects to review what we learned in the last section.

Our PostCreate will implement get() to handle state one of Table 9.9, a reprint of our finite-state machine for views that create objects using Django forms. States 2 and 3 will be handled by the post() method.

Image

Table 9.9: View States

As in TagCreate, we use class attributes to keep elements used in both views easily accessible in a single place, as shown in Example 9.25.

Example 9.25: Project Code

blog/views.py in 639cc39b30

 1   from django.shortcuts import (  2       get_object_or_404, ...

Get Django Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.