Package: django-mockups-ng
This app aims to provide a simple way of loading masses of randomly generated
test data into your development database. You can use a management command to
load test data through command line.Usually you add test data through the admin to see how your site looks with non
static pages. You export data by usingdumpdatato send it to your
colleagues or to preserve it before you make amanage.py reset appand so
on. Your site gets more and more complex and adding test data gets more and
more annoying.This is the usecase where mockups should help you to save time that can
actually be spent on hacking.InstallationYou must make themockupspackage available on your python path.  Either
drop it into your project directory or install it from the python package index
withpip installdjango-mockups.To use the management command you must add'mockups'to theINSTALLED_APPSsetting in your django settings file. You don’t need to do
this if you want to use themockupspackage only as library.Management commandThemockupsaccepts the following syntax:django-admin.py mockups [options] app.Model:# [app.Model:# ...]Its nearly self explanatory. Supply names of models, prefixed with its app
name. After that, place a colon and tell the command how many objects you want
to create. Here is an example how to create three categories and twenty
entries for you blogging app:django-admin.py mockups blog.Category:3 blog.Entry:20Voila! You have ready to use testing data populated to your database. The
model fields are filled with data by producing randomly generated values
depending on the type of the field. E.g. text fields are filled with lorem
ipsum dummies, date fields are populated with random dates from the last
years etc.There are a few command line options available. Mainly to control the
behavior of related fields. If foreingkey or many to many fields should be
populated with existing data or if the related models are also generated on
the fly. Please have a look at the help page of the command for more
information:django-admin.py help mockupsUsing mockups as tool for unittestsIt has proofed that mockups have a great use for unittests. It has always
bugged me that creating complex models for testing their behaviour was
complicated. Sometimes models have strict restrictions or many related objects
which they depend on. One solution would be to use traditional fixtures
dumped from your production database. But while in development when database
schemes are changing frequently, its hard to maintain all fixtures and to know
exactly which objects are contained in the dumps etc…Mockups to the rescue! It lets you automatically generate models and all
of their dependecies on the fly. Have a look at the following examples.Lets start with the very basics. We create aMockupinstance for theEntrymodel and tell it to create ten model instances:from mockups import Mockup
mockup = Mockup(Entry)
entries = mockup.create(10)Now you can play around and test your blog entries. By default dependecies of
foreignkeys and many to many relations are solved by randomly selecting an
already existing object of the related model. What if you don’t have one yet?
You can provide thegenerate_fkattribute which allows the mockup
instance to follow foreignkeys by generating new related models:mockup = Mockup(Entry, generate_fk=True)This generates new instance forallforeignkey fields ofEntry. Its
possible to limit this behaviour to single fields:mockup = Mockup(Entry, generate_fk=['author'])This will only create new authors automatically and doesn’t touch other
tables. The same is possible with many to many fields. But you need
additionally specify how many objects should be created for the m2m relation:mockup = Mockup(Entry, generate_m2m={'categories': (1,3)})All created entry models get one to three new categories assigned.Setting custom values for fieldsHowever its often necessary to be sure that a specific field must have a
specific value. This is easily achieved with the use ofFactory:class PonyFactory(Factory):
    pub_date = generators.StaticGenerator(datetime(2010, 2, 1))

class PonyMockup(Mockup):
    factory = PonyFactory

mockup = PonyMockup(Entry)MoreThere is so much more to explore which might be useful for you and your
projects:There are ways to register customMockupsubclasses with models
that are automatically used when callingmockupson the model.More control for related models, even with relations of related models…
(e.g. by usinggenerate_fk=['author','author__user'])Custom constraints that are used to ensure that created the models are
valid (e.g.uniqueandunique_togetherconstraints which are
already handled by default)I hope to explain this in the future with more details in a documentation. It
will be written but is not finished yet. I wanted to get this project out to
support you in development. But since its only python code you can easily study
the source on your own and see in which ways it can be used. There are already
some parts documented with doc strings which might also be helpful for you.