Ruben Quinones
Ruben Quinones

Reputation: 2472

Choices from model in Django

I have a model that picks up the choices defined in CHOICES like this:

CHOICES = (
    ('1', '1'),
    ('2', '2'),
    ('3', '3'),
)

class select(models.Model):
  first = models.CharField(max_length=3, choices=CHOICES)
  second = models.CharField(max_length=3, choices=CHOICES)

I would like to be able to add, remove or change choices in the admin page. So my approach would be to have CHOICES as a model, but I dont know if this is the right way to do this. If it is, then how can I set it? Thanks.

Upvotes: 1

Views: 844

Answers (1)

Bryan
Bryan

Reputation: 771

You want something like a ManyToMany field, not choices on a Character field. More info here: http://docs.djangoproject.com/en/1.0/ref/models/fields/#django.db.models.ManyToManyField

Upvotes: 5

Related Questions