Re: Newbie Django queryset question

2012-03-15 Thread Shawn Milochik

On 03/15/2012 11:22 PM, Murilo Vicentini wrote:
Uhmmm, thank you a lot. That was what I was looking for! Sorry for 
wasting your time. One last question, does this double-underscore 
notation work at my html template? Because after filtering I will want 
to display the information of the different models at one row of my table.




Try it and find out. ^_^

Also, a word of caution for things like that -- they lead to amazingly 
slow pages. Make sure you read up on select_related before you go crazy 
referring to related items in your templates (or views, for that matter).


https://docs.djangoproject.com/en/1.3/ref/models/querysets/#select-related

I suggest ignoring the "depth" kwarg and using the method demonstrated 
with "room__building" as an example. But read the preceding text first 
to understand how it works in general.



--
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.



Re: Newbie Django queryset question

2012-03-15 Thread Murilo Vicentini
Uhmmm, thank you a lot. That was what I was looking for! Sorry for wasting 
your time. One last question, does this double-underscore notation work at 
my html template? Because after filtering I will want to display the 
information of the different models at one row of my table.

On Friday, March 16, 2012 12:09:44 AM UTC-3, Shawn Milochik wrote:
>
>  You can certainly use Q objects to query across models, just as you can 
> in a normal QuerySet, by using the double-underscore notation.
>
>
> https://docs.djangoproject.com/en/1.3/topics/db/queries/#lookups-that-span-relationships
>
>
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/sXps3T_6bDEJ.
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.



Re: Newbie Django queryset question

2012-03-15 Thread Shawn Milochik
You can certainly use Q objects to query across models, just as you can 
in a normal QuerySet, by using the double-underscore notation.


https://docs.djangoproject.com/en/1.3/topics/db/queries/#lookups-that-span-relationships


--
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.



Re: Newbie Django queryset question

2012-03-15 Thread Murilo Vicentini
But if I got it correctly I can use Q objects to make complex filters but 
they only apply to one model, what I need is a combination of the models. 
And since the search can return more than one (or even zero) objects I 
can't use get() to see the related objects. 

On Thursday, March 15, 2012 9:58:52 PM UTC-3, Shawn Milochik wrote:
>
>  If you don't know which fields your users will be searching on in 
> advance, you'll have to create Q objects and dynamically build your query 
> in your view.
>
>
> https://docs.djangoproject.com/en/1.3/topics/db/queries/#complex-lookups-with-q-objects
>
>
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/P8Jn4YsOabEJ.
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.



Re: Newbie Django queryset question

2012-03-15 Thread Shawn Milochik
If you don't know which fields your users will be searching on in 
advance, you'll have to create Q objects and dynamically build your 
query in your view.


https://docs.djangoproject.com/en/1.3/topics/db/queries/#complex-lookups-with-q-objects


--
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.



Newbie Django queryset question

2012-03-15 Thread Murilo Vicentini
Hey guys, sorry if this is a newbie question, but I'm new at django and I'm 
having a real hard time trying to figure out how to solve this. So I have 
this model.
class Run(models.Model):
speccpus = models.ForeignKey('Speccpu')
hosts = models.ForeignKey('Host')

Task = models.IntegerField()
Path = models.CharField(max_length = 300)
Date_Time = models.DateTimeField()

class Host(models.Model):
Name = models.CharField(max_length = 100)
ip_addr = models.IPAddressField()
admin_ip_addr = models.IPAddressField()
Location = models.CharField(max_length = 100)

class Speccpu(models.Model):
Version = models.CharField(max_length = 50)
Base_score = models.IntegerField()
Peak_score = models.IntegerField()

So what i need to do is search a for an input in any of this fields, so 
they can return more than one row of a table, since i need to display on 
the screen a table containing the Run - Task, Path, Date_Time fields, also 
the Host Name field, and the Speccpu Base and peak score. I was thinking 
about doing something like an inner join of this three models, and then 
filtering. But i can't manage to do it. Does anyone have any ideia of how i 
can do it using the queryset API?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/rEEVGXSHL4AJ.
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.