Hi

i would use raw SQL to retrieve models, that would be the fastest way i
quess:
http://docs.djangoproject.com/en/dev/topics/db/sql/

from django.db import connection

cursor = connection.cursor()
cursor.execute(...Sqlquery...)
.......
.......

Other way could look like this:

result = []
all_models=MyModel.objects.all()
for x in all_models:
   if x.width>x.maxwidth:
       result.append(x)
.......
.......


Hope it helps.

R.


Costin Stroie-2 wrote:
> 
> 
> Hi!
> 
> I have the following model:
> 
> class MyModel(models.Model):
>     maxwidth = models.IntegerField(Maximum width', default = '0')
>     width = models.IntegerField('Width', default = '0')
> 
> I need to perform a query similar to this:
> 
> SELECT * FROM mymodel WHERE width > maxwidth;
> 
> The result should be a queryset, since I need it as filter in a long
> chain of filters. Moreover, I need it to be able to be OR'ed to some
> other querysets, so I found a simple .extra(where = ['width >
> maxwidth']) won't work (the WHERE clause is placed in a wrong
> position).
> 
> How can I do it? Maybe a forged Q object? Well, I'm stuck.
> > 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Compare-the-fields-of-the-same-model-tp21547991p21578262.html
Sent from the django-users mailing list archive at Nabble.com.


--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to