Search code examples
djangoforeign-keysfixture

Making a django Fixture that gets 100 items from each Table, or follows foreign keys


I need to create some fixtures for django test. Does anyone know of a shortcut that lets me get x number of rows from every table in database and serialize it?

Background: I have Multiple tables with 10's of millions of entries. I have tried to use the ./manage.py dumpdata, but in addition to taking too long there is no way fixture should be that large. Each table has multiple foreign keys.

The Problem: The code I am trying to test frequently calls select_related() Meaning I need all the foreign key relationships filled in.

Does anyone know of any tools that can help me follow foreign relationships for serializing DB data??? Any suggestions would be greatly appreciated. Thank you for your time.


Solution

  • I have used the django-autofixture pluggable apps in a couple projects. You could give that a shot. Instead of using data from your database for tests, create a development database filled with autofixtures.

    This link has a few other examples of similar pluggable apps.

    http://djangopackages.com/grids/g/fixtures/