Thanks Carl, I wasn't aware of that function, that works :) Sometimes normalization can just get you in trouble, slow things down. My question was mainly regarding the efficiency in terms of storage, and how you query that if you store the short version. I would not consider dividing the data up into more models at the time. I would use something like haystack with elasticsearch to index the human readable names if I needed them and that display function is a life saver. Thanks all.
On Wednesday, 17 December 2014 11:56:08 UTC-5, Radomir Wojcik wrote: > > 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/2f8b67d6-8e98-460a-b7ee-210aef311ce6%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.