I have two files:
choices.py
class SomeChoice:
name = u"lorem"
class AnotherChoice:
name = u"ipsum"
# etc...
models.py
from django.db import models
import choices
class SomeModel(models.Model):
CHOICES = (
(1, choices.SomeChoice.name),
(2, choices.AnotherChoice.name),
# etc...
)
somefield = models.IntegerField('field', choices=CHOICES)
The problem: classes from choices.py need something like a primary key to be stored in my database. Here I write these keys (1, 2, ...) by hand, but this is ugly.
For instance, I don't want to do that:
class SomeChoice:
id = 1
name = "lorem"
class AnotherChoice:
id = 2
name = "lorem"
So my question is: what is the best way to store python classes into a database ?
Please excuse my ugly english. If you need more informations, just tell me. ;-)