Search code examples
pythondjangodjango-admin

Add entries to the choices of a field through the admin site?


I have a model with some default entries in a choices field. I was wondering if it was possible for the admin to add and remove entries to the choices from the admin site. The only other option I see at the moment is to have a separate table for the entries, but the spec specifically says to only use one table and I'm fairly new to Django. The current model code is very basic, and I haven't added any forms to admin.py, only registered my model. Example code:

class Contact(models.Model):
    #some other fields here...
    ...
    TYPES = (
        ('op1','option1'),
        ('op2','option2'),
        ('op3','option3')   
    )

    option = models.CharField(
        max_length=3,
        choices=TYPES,
        default='op1'    
    )

I want the super user to be able to click an add/remove type button on the admin page to open a new box which will allow them to edit the possible types.


Solution

  • Turns out I had to make a new model after all. it's fine, the admin site works as it needs to.