Hi all,

I am getting confused regarding the use of constants and would be keen to
know how the rest of you handle constants in your models. Ofcourse I could
handle it easily similar to how it has been handled here:
https://docs.djangoproject.com/en/1.7/ref/models/fields/#django.db.models.Field.choices

But I wanted to put the constants in a separate class on their own. This is
what I hav so far:

models.py

class TaskStatus(models.Model):

    CANCELLED = 0
    REQUIRES_ATTENTION = 1
    WORK_IN_PROGRESS = 2
    COMPLETE = 3

    STATUS_TYPES = (
        (CANCELLED, 'Cancelled'),
        (REQUIRES_ATTENTION, 'Requires attention'),
        (WORK_IN_PROGRESS, 'Work in progress'),
        (COMPLETE, 'Complete'),
    )

    status = models.IntegerField(choices=STATUS_TYPES,
default=REQUIRES_ATTENTION)
    class Task(models.Model):
    status = models.ManyToManyField(TaskStatus,
default=TaskStatus.REQUIRES_ATTENTION)


In my case, a Task can have one or more TaskStatus. I do not wish to store
the TaskStatus in the database since they are simply constants.

Does anyone have a better way of how I can approach this?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEAUGdX-eGA9mY5h%2Bj0yDHeFe_cX%3DP_i0ToRjp%2BDbRsDGCPaDw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to