Generating the Development Data
Explore how to define data models and generate realistic development data using Faker and model_bakery. Understand how to register models with Django admin and safely populate your database for testing filters, bulk actions, and search features.
Custom admin filters, bulk actions, and search interfaces are hard to validate against an empty database. To verify how these admin changes behave, we need a realistic dataset with enough records to test edge cases.
First, we’ll define the data models, then use development data generation tools to create enough non-production data for testing so the admin customizations can be tested against realistic data.
Defining the quiz data model
Our sample application is a simple quiz system composed of three models: Author, Question, and Choice. We define these models inside the sample_app/models.py file. We use modern Python f-strings for our string representations, completely avoiding legacy string formatting patterns.
Lines 9, 19, and 29: Implement the
__str__methods using ...