On 10/29/07, dimitri pater <[EMAIL PROTECTED]> wrote: > > Hi, > > I want to prepopulate a database with the weeknumber (as a separate > filed) from a given date. This is what the models looks like: > class Item(models.model): > day=models.DateField() > weekno=models.SmallIntegerField(prepopulate_from(??day??,) > > I know that datetime.date.isocalender(day)[1] returns the weeknumber, > but I have no idea how to put this in the model. > What I want to achieve in the end is filtering objects from the db > (obj=item.objects.filter(weekno=current_week)) > > Your help is appreciated, > Dimitri
Override your model's save method [1] def save(self, **kwargs): self.weekno = datetime.date.isocalender(self.day)[1] super(Item, self).save(**kwargs) Jonathan. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---