Posts

Part 8: Adding third-party packages

  We’ve built our web-poll application and will now look at third-party packages. One of Django’s strengths is the rich ecosystem of third-party packages. They’re community developed packages that can be used to quickly improve the feature set of an application. This tutorial will show how to add  Django Debug Toolbar , a commonly used third-party package. The Django Debug Toolbar has ranked in the top three most used third-party packages in the Django Developers Survey in recent years. Where to get help: If you’re having trouble going through this tutorial, please head over to the  Getting Help  section of the FAQ. Installing Django Debug Toolbar ¶ Django Debug Toolbar is a useful tool for debugging Django web applications. It’s a third-party package maintained by the  Jazzband  organization. The toolbar helps you understand how your application functions and to identify problems. It does so by providing panels that provide debug information about the curr...

Part 7: Customizing the admin site

Image
  Customize the admin form ¶ By registering the  Question  model with  admin.site.register(Question) , Django was able to construct a default form representation. Often, you’ll want to customize how the admin form looks and works. You’ll do this by telling Django the options you want when you register the object. Let’s see how this works by reordering the fields on the edit form. Replace the  admin.site.register(Question)  line with: polls/admin.py ¶ from django.contrib import admin from .models import Question class QuestionAdmin ( admin . ModelAdmin ): fields = [ "pub_date" , "question_text" ] admin . site . register ( Question , QuestionAdmin ) You’ll follow this pattern – create a model admin class, then pass it as the second argument to  admin.site.register()  – any time you need to change the admin options for a model. This particular change above makes the “Publication date” come before the “Question” field: This is...