Monday, February 23, 2015

Re: How to handle model constants


>>> 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?
>>>

I just read this a bit closer. I think what you mean is that you don't want a separate enumeration DB table that lists all of your choices with their integer codes and then your statuses link to it via FK's, etc. That's perfectly fine, and that should be how it works since you have enumerated all of the possible outcomes in your tuples. Since you have provided a list of choices to Django, it will validate that only those choices are allowed when forms are submitted, etc. as a bonus.

TL;DR; Unless you've hit a specific problem, it looks like you are doing it right.

https://docs.djangoproject.com/en/1.7/ref/models/fields/#choices

-James

--
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+unsubscribe@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/CA%2Be%2BciW6Nk076DGurtJQ6t9gFj%2BsLgKkAdwtEJdYcvxRwq9wrA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment