@ user3186459 This is a great question.
To do this well, you'll need a combination of Factory Boy , Faker, and customizable control commands .
Factory Boy lets you create patterns to create valid objects, and Faker generates fake data.
When you install Factory Boy, pip install factory_boy , you also get Faker.
Considering,
from django.db import models class User(models.Model): name = models.CharField(max_length=64) address = models.CharField(max_length=128) phone_number = models.CharField(max_length=32)
You can define Factory as follows:
import factory import factory.django class UserFactory(factory.django.DjangoModelFactory): class Meta: model = User name = factory.Faker('name') address = factory.Faker('address') phone_number = factory.Faker('phone_number')
You can then create fake users by calling UserFactory.create() .
One way to get your 200 fake users is to go into the python manage.py shell and do:
>>>
Another way that can give you more flexibility is to create a custom management team.
Here is a simple example:
from django.core.management.base import BaseCommand
And you run it through the command line using python manage.py seed or python manage.py seed --users 50 , for example.
source share