简体   繁体   English

如何在Django模型中为任务状态建模

[英]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? 在我的django应用程序中, Task可以具有PENDING or FINISHED status 。哪种方法是在django模型中建模的最佳方法?

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 ? 理想情况下,我想为用户提供一个dropdown list ,供他选择状态。有人可以建议我对此建模吗?

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. 它可以是任何类型的字段,例如CharInt但您可以提供它的选择列表,这些列表将以html形式显示为下拉列表。

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')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM