On Monday, April 18, 2011 11:57:37 AM UTC+1, Daniel Roseman wrote:
>
> On Monday, April 18, 2011 9:10:30 AM UTC+1, o_r wrote:
>>
>> Hello.
>>
>> I have this model:
>>
>> class MyModel(models.Model):
>> string = models.CharField(max_length=96,unique=True,db_index=True)
>> mother=models.ForeignKey('self',null=True,blank=True)
>>
>> top=models.ForeignKey('self',null=True,blank=True,related_name="Top")
>>
>> I need to make a query which will return all those instances where
>> mother and top is the same. Is this possible using the orm, or do I
>> need to use raw?
>>
>> Thanks!
>>
>> Odd-R.
>
>
> Use F() objects:
>
> MyModel.objects.filter(mother=F(top))
>
>
> http://docs.djangoproject.com/en/1.3/topics/db/queries/#filters-can-reference-fields-on-the-model
> --
> DR.
>
Sorry, that should have been:
MyModel.objects.filter(mother=F("top"))
--
DR.
--
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.