python - Grouping Data by field in Django -
as chapters grouped season:
season 1: chapter 1 chapter 2 chapter 3 chapter 4
season 2: chapter 1 chapter 2 chapter 3
example image http://i.stack.imgur.com/svaqm.png
#models.py class serie(models.model): # optional fields def serie_chapter(self): return self.seriechapter_set.order_by("season","chapter") class seriechapter(models.model): serie = models.foreignkey(serie) name = models.charfield(max_length=100, unique=true) slug = models.slugfield(max_length=100, unique=true) season = models.integerfield(db_index=true, choices=choices_season) chapter = models.integerfield(choices=choices_episode) created_at = models.datetimefield(auto_now=true)
so, can add chapters per season?
thanks.
you can add 1 more class
class series_chapter(models.model): series=models.foreignkey(serie) chapter=models.foreignkey(seriechapter)
in class seriechapter won't need
serie=models.foreignkey(serie)
for season 1 want add episode1 , episode2 first add series , chapters in respective models. in series_chapter
s1c1=series_chapter.objects.create(series=instance_of_serie,chapter=instance_of_seriechapter)#for chapter 1 s1c2=series_chapter.objects.create(series=instance_of_serie,chapter=instance_of_seriechapter)#for chapter 2
Comments
Post a Comment