django-dilla: Uber-cool DB spammer for Django

I remember one of my Django projects wherein I was asked to populate the database with 30k dummy rows of data. So what I did was to find myself a dictionary of words for string-based fields, use it for populating the fields for the objects of that specific model and then push them to the database. Unsurprisingly, it took me hours to write the code and hours to finish executing it. Had I known that there is a tool that generates data randomly, I would have saved a lot of time I used to do all the extra work.

Django-dilla does just that. It lets you spam your database with dummy information with just a single command.

Consider the model below, which is designed for the sake of having a variety of Field types.

 

Running Dilla with cycles set to 1000, ie. generate 1000 records, only took a few seconds to execute:

 

Showing the first two results:

 

And now there’s dummy data! It’s fast and easy! There’s just one problem though.. it’s very ugly. What kind of person is named “reapplied hat tinting puppy tim’s nationalism’s” and has some kind of code for a phone number?

To get around this problem, Dilla provides a way to customize the handler for a field. It can be a global handler which returns data for a particular Field type, or a strict handler which handles specific attributes in a model. Here is a custom spammer that generates the data that goes in the phone field.

 

The improved results are as follows:

References: https://github.com/aerosol/django-dilla