> Den 04/05/2015 kl. 14.21 skrev Erik Cederstrand <erik+li...@cederstrand.dk>: > > class Month(models.Model): > year = models.IntegerField() > month = models.PositiveSmallIntegerField() > > def add_months(self, n): > assert n >= 0 > dy, dm = divmod(self.month + n, 12) > self.year += dy > self.month += dm
Sorry, that's supposed to be: def add_months(self, n): assert n >= 0 dy, self.month = divmod(self.month + n, 12) self.year += dy Disclaimer: This possibly only applies to the Gregorian calendar. Read up on the others as needed: http://en.wikipedia.org/wiki/List_of_calendars :-) Erik -- 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/B025BC73-DE58-4E4F-9F55-B94CC990381E%40cederstrand.dk. For more options, visit https://groups.google.com/d/optout.