Package: django-seeder
Fork fromdjango-seedSource’s documentation:Django-seeduses thefakerlibrary to generate test data for your Django models. This has been “hard-forked” fromdjango_fakerin order to support newer versions of Python and DjangoDjango-seed allows you to write code to generate models, and seed your database with one simplemanage.pycommand!InstallationConfigurationUsageUsing with commandUsing with codeTestsLicenseInstallationTo install django-seed, use pip:pip install django-seederOr to install from source:python setup.py installConfigurationAdd it to your installed apps insettings.py:INSTALLED_APPS = (
    ...
    'django_seeder',
)UsageNote: When seeding models with Foreign Keys, you need to make sure that those models are seeded first. For example, if a model in appAhas a foreign key to a model in appB, you must seed appBfirst.Using with commandWithdjango-seed, you can seed your database with test data from the command line using themanage.py seedcommand.Ex: Seed 15 of each model for the appapi:$pythonmanage.pyseedapi--number=15That’s it! Now you have 15 of each model seeded into your database.Should you need, you can also specify what value a particular field should have. For example, if you want to seed 15 ofMyModel, but you needmy_fieldto be the same on all of them, you can do it like this:$pythonmanage.pyseedapi--number=15--seeder"MyModel.my_field""1.1.1.1"This is the command equivalent to doing it in Python:seeder.add_entity(MyModel,10,{'my_field':'1.1.1.1',})Using with codedjango-seedprovides methods to easily seed test databases for your Django models. To seed your database with Model instances, importSeed, get aseederinstance, and use theadd_entitymethod.Ex: seeding 5Gameand 10Playerobjects:fromdjango_seederimportSeedseeder=Seed.seeder()frommyapp.modelsimportGame,Playerseeder.add_entity(Game,5)seeder.add_entity(Player,10)inserted_pks=seeder.execute()The seeder uses the name and column type to populate the Model with relevant data. If django-seed misinterprets a column name or column type andAttributeError(field)is thrown, you can still specify a custom function to be used for populating a particular column, by adding a third argument to theadd_entity()method:seeder.add_entity(Player,10,{'score':lambdax:random.randint(0,1000),'nickname':lambdax:seeder.faker.email(),})seeder.execute()Django-seed does not populate auto-incremented primary keys, insteadseeder.execute()returns the list of inserted PKs, indexed by class:printinserted_pks{<class'faker.django.tests.Player'>: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],<class'faker.django.tests.Game'>: [1, 2, 3, 4, 5]}You may specify a different locale by passing it in the constructor of the seeder. Defaults tosettings.LANGUAGE_CODEseeder=Seed.seeder(locale='sv_SE')seeder.faker.city()# 'Västerås'LocalizationSeed.seeder()can take a locale as an argument, to return localized data.
You can find all possible locales infaker’s documentationIn order to apply localization, do the next:seeder=Seed.seeder('it_IT')TestsTo run django tests in a django environment, first make sure you have the packages fromrequirement-test.txtinstalled, then run the following:$pythonruntests.pyor if you havedjango_seederin INSTALLED_APPS:$pythonmanage.pytestdjango_seederLicenseMIT. SeeLICENSEfor more details.