The official django doc uses this as an example (see below). Is there any 
point to storing 'FR' instead of 'Freshman" so the choice matches what is 
stored? Is it faster at all? Saves room? What about for querying the data? 
Then you have to lookup the symbol 'FR' in the tuple if someone wants to 
query by 'Freshman'. 

What is the best practice? Is it even more efficient if integers were used, 
like 1 value to represent Freshman and so on? To me it makes sense to store 
'Freshman' as 'Freshman' but I'd like to get some insight.

from django.db import models

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

    def is_upperclass(self):
        return self.year_in_school in (self.JUNIOR, self.SENIOR)

-- 
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/e0a71f13-1541-437b-a7b9-24c06f08c7e5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to