Search code examples
pythondjangomodelstatus

how to model status for a task in django model


In my django app, a Task can have PENDING or FINISHED status.Which is the best way to model this in a django Model?

class Task(models.Model):
    taskname = models.CharFiled(...)
    taskdate = models.DateTimeField()
    status = models.CharFiled(...)

Is this the proper way? Ideally I would like to provide the user with a dropdown list from which he can choose the status.Can someone suggest how I can model this ?


Solution

  • It can be any type of field like Char or Int but you can provide list of choices to it which will show as dropdown in the html form.

    Reference at Model field Choices

    YEAR_IN_SCHOOL_CHOICES = (
        ('FR', 'Freshman'),
        ('SO', 'Sophomore'),
        ('JR', 'Junior'),
        ('SR', 'Senior'),
    )
    class Student(models.Model):
        year_in_school = models.CharField(max_length=2,
                                      choices=YEAR_IN_SCHOOL_CHOICES, default='FR')