Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: Setting up database code tables (aka reference tables, domain tables)?

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?

like image 669
User Avatar asked Oct 25 '22 14:10

User


1 Answers

You'll want to use a fixture for that.

like image 64
Ignacio Vazquez-Abrams Avatar answered Nov 09 '22 02:11

Ignacio Vazquez-Abrams