Hi Serek,
Try this
def doMagic(self):
date = '2010-05-04'
#//here I need to take 10 conencted Bbb objects whcich data is less
then date
previous10days = Bbb.objects.filter(date__lt=date).order_by('data')
Also read up about managers
http://docs.djangoproject.com/en/1.2/topics/db/managers/ in case you should
consider using it (depending upon how much magic is required from your
function).
Regards
Chris
-----Original Message-----
From: [email protected] [mailto:[email protected]] On
Behalf Of serek
Sent: 17 February 2011 00:51
To: Django users
Subject: how can I filter related (foreign key) objects?
Hi
I have not idea how to describe my problem, so I show pice of code:
class Aaa(models.Model):
name = models.CharField(max_length=200, unique=True)
is_active = models.BooleanField()
class Meta:
ordering = ('name',)
def doMagic(self):
date = '2010-05-04'
//here I need to take 10 conencted Bbb objects whcich data is less
then date
previous10days = self.bbb_set.filter(Bbb.date <
date).order_by('data')
class Bbb(models.Model):
date = models.DateField()
value = models.DecimalField(max_digits=7, decimal_places=2)
aaa = models.ForeignKey(Aaa)
a = Aaa()
a.doMagic throw error that Bbb.date is undefined - what can be wrong?
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
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.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
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.