5

Often times applications will need some database code tables (aka reference tables or domain tables or lookup tables). Suppose I have a model class called Status with a field called name that could hold values like:

Canceled
Pending
InProgress
Complete

Where and at what point would I setup these values in Django? Its like a one time operation to setup these values in the database. Infrequently, these values could be added to.

And I guess more generically, how do you initialize models with data? For example, say I had a model for holding the make of a car and I want to initialize this list with a set of known values. How would I do this?

User
  • 62,498
  • 72
  • 186
  • 247
  • Could you use [choices](http://docs.djangoproject.com/en/dev/ref/models/fields/#choices) for this or it really needs to be in the database so you can add status names through admin? – Davor Lucic May 16 '10 at 22:16
  • For this particular application I'm debating using choices, but for a flexible design I wanted to know how to use db tables. And in general I'd like to know how to do this. – User May 16 '10 at 22:26

1 Answers1

3

You'll want to use a fixture for that.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358