tags:

views:

18

answers:

1

I need to populate sample data for Django Image/File fields in automated python code.

I want to initialize Django ImageFields and FileFields with some sample images and data files that are stored in my "site_media" directory of my Django project.

What would the code look like? This is not for testing, I want to autopopulate sample data into my Django website user's accounts (including this sample Imgae/File media.)

+1  A: 

If I understand you correctly you want to use fixtures, basically a JSON formatted file that holds data that will be put into the project database. They can be executed through the django-admin command like :

 django-admin.py loaddata mydata.json

see http://docs.djangoproject.com/en/1.2/ref/django-admin/#loaddata-fixture-fixture

Jasper