Note: There are of course many other tests you can run. Use your discretion, but we'll expect you to do at least the tests above.

The following section shows screenshots of a site that implements the requirements above.

Screenshots

The following screenshot provide an example of what the finished program should output.

List of all blog posts

This displays the list of all blog posts (accessible from the "All blogs" link in the sidebar). Things to note:

The sidebar also lists the logged in user.

Individual blog posts and bloggers are accessible as links in the page.

Pagination is enabled (in groups of 5)

Ordering is newest to oldest.

List of all bloggers

This provides links to all bloggers, as linked from the "All bloggers" link in the sidebar. In this case we can see from the sidebar that no user is logged in.

Blog detail page

This shows the detail page for a particular blog.

Note that the comments have a date and time, and are ordered from oldest to newest (opposite of blog ordering). At the end we have a link for accessing the form to add a new comment. If a user is not logged in we'd instead see a suggestion to log in.

Add comment form

This is the form to add comments. Note that we're logged in. When this succeeds we should be taken back to the associated blog post page.

Author bio

This displays bio information for a blogger along with their blog posts list.

Create a page with a form for adding new comments (remember to make this only available to logged in users!)

Hints and tips

This project is very similar to the LocalLibrary tutorial. You will be able to set up the skeleton, user login/logout behaviour, support for static files, views, URLs, forms, base templates and admin site configuration using almost all the same approaches.

Some general hints:

The index page can be implemented as a basic function view and template (just like for the locallibrary).

The list of blog posts for a particular author can be created by using a generic list Blog list view and filtering for blog object that match the specified author.

You will have to implement get_queryset(self) to do the filtering (much like in our library class LoanedBooksAllListView) and get the author information from the URL.

You will also need to pass the name of the author to the page in the context. To do this in a class-based view you need to implement get_context_data() (discussed below).

The add comment form can be created using a function-based view (and associated model and form) or using a generic CreateView. If you use a CreateView (recommended) then:

You will also need to pass the name of the blog post to the comment page in the context (implement get_context_data() as discussed below).

The form should only display the comment "description" for user entry (date and associated blog post should not be editable). Since they won't be in the form itself, your code will need to set the comment's author in the form_valid() function so it can be saved into the model (as described here — Django docs). In that same function we set the associated blog. A possible implementation is shown below (pk is a blog id passed in from the URL/URL configuration).

You will need to provide a success URL to redirect to after the form validates; this should be the original blog. To do this you will need to override get_success_url() and "reverse" the URL for the original blog. You can get the required blog ID using the self.kwargs attribute, as shown in the form_valid() method above.

We briefly talked about passing a context to the template in a class-based view in the Django Tutorial Part 6: Generic list and detail views topic. To do this you need to override get_context_data() (first getting the existing context, updating it with whatever additional variables you want to pass to the template, and then returning the updated context). For example, the code fragment below shows how you can add a blogger object to the context based on their BlogAuthor id.

Assessment

The assessment for this task is available on Github here. This assessment is primarily based on how well your application meets the requirements we listed above, though there are some parts of the assessment that check your code uses appropriate models, and that you have written at least some test code. When you're done, you can check out our the finished example which reflects a "full marks" project.

Once you've completed this module you've also finished all the MDN content for learning basic Django server-side website programming! We hope you enjoyed this module and feel you have a good grasp of the basics!