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

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,

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

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

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

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 =

Re: many-to-many queryset question

2012-01-07 Thread Carsten Fuchs
Hi Peter, Am 2012-01-07 03:40, schrieb Peter of the Norse: One possibility is to try two excludes. bad_authors = Authors.objects.exclude(pk__in=SetOfAuthors) qs = Entry.objects.exclude(authors__in=bad_authors) This will return all entries that don't have authors in SetOfAuthors. It might

Re: many-to-many queryset question

2012-01-06 Thread Peter of the Norse
One possibility is to try two excludes. bad_authors = Authors.objects.exclude(pk__in=SetOfAuthors) qs = Entry.objects.exclude(authors__in=bad_authors) This will return all entries that don't have authors in SetOfAuthors. It might even be easier, if you can skip creating SetOfAuthors in the

Re: many-to-many queryset question

2011-12-06 Thread Felipe Morales
could you possibly show the query generated?... # print qs.query 2011/12/6 Carsten Fuchs > Hi all, > > looking at the example models Author and Entry at >

many-to-many queryset question

2011-12-06 Thread Carsten Fuchs
Hi all, looking at the example models Author and Entry at https://docs.djangoproject.com/en/1.3/topics/db/queries/, I would like to run a query like this: SetOfAuthors = Authors.objects.filter(...) qs = Entry.objects.filter(authors__in=SetOfAuthors) such that (pseudo-code):

Re: QuerySet Question

2009-11-14 Thread Chris
I have got tracks working with the extra() function. I do the following: tracks.extra(select={'owned':'SELECT Count(*) FROM shop_track_owners WHERE track_id=shop_track.id and user_id='+str(user.id)}) This works great for tracks. However, how will I do this when I'm just passing a queryset of

Re: QuerySet Question

2009-11-13 Thread Matt Schinckel
On Nov 14, 1:01 am, Chris wrote: > Thanks for your reply. > > From reading around it sounds as though I am probably not meant to > solve this in the template (though this does seem like the easier > option). > > I have figured out that I could solve this through an

Re: QuerySet Question

2009-11-13 Thread Chris
Thanks for your reply. >From reading around it sounds as though I am probably not meant to solve this in the template (though this does seem like the easier option). I have figured out that I could solve this through an SQL statement as follows: select *, (select Count(*) FROM shop_track_owners

Re: QuerySet Question

2009-11-12 Thread Tomasz Zieliński
On 12 Lis, 16:12, Chris wrote: > Is there a way of getting a model function to access user details so > that I can do a simple "if track.owned" in the template? Is there a > better solution to doing it in the view? Is there something I have not > thought of? What

QuerySet Question

2009-11-12 Thread Chris
Hi all, I am new to Django and I am having a little trouble. The situation: I am setting up a music selling website (similar to iTunes) for a uni project. There are Tracks, Albums and Artists as well as users via Django auth. A user can own a track. This is accomplished with a many to many field

newbie queryset question

2009-08-11 Thread joep
I have a model which contains a list of users and a list of groups that can access the model, e.g,, readers = models.ManyToManyField(User, blank=True, null=True,) reader_groups = models.ManyToManyField(Group, blank=True, null=True,) where User and Group are the standard django auth

Re: QuerySet question, getting latest 3 objects filtered by a key.

2009-06-22 Thread Alex Gaynor
On Mon, Jun 22, 2009 at 1:58 PM, Sean Brant wrote: > > This is best explained with an example. > > i have a model for Stats > > class Stat(models.Model): >key = models.CharField(max_length=50) >value = models.TextField() >pub_date = models.DateTimeField() > > so

QuerySet question, getting latest 3 objects filtered by a key.

2009-06-22 Thread Sean Brant
This is best explained with an example. i have a model for Stats class Stat(models.Model): key = models.CharField(max_length=50) value = models.TextField() pub_date = models.DateTimeField() so if i create a few stat objects lets say these. stat1 = Stat(key='total_books_sold',

Re: QuerySet Question - Selecting a Single Field

2007-06-05 Thread Russell Keith-Magee
On 6/6/07, Bryan Veloso <[EMAIL PROTECTED]> wrote: > > > This will grab _all_ score objects, and sort them by baseball score. > > If there isn't a baseball score, then 'baseball' will have a value of > > None, which is still a sortable value. > > Alright, so just to be safe, I really shouldn't be

Re: QuerySet Question - Selecting a Single Field

2007-06-05 Thread Bryan Veloso
> This will grab _all_ score objects, and sort them by baseball score. > If there isn't a baseball score, then 'baseball' will have a value of > None, which is still a sortable value. Alright, so just to be safe, I really shouldn't be showing the values for all players, since that risks showing

Re: QuerySet Question - Selecting a Single Field

2007-06-05 Thread Russell Keith-Magee
On 6/6/07, Bryan Veloso <[EMAIL PROTECTED]> wrote: > > > Score.objects.order_by('-baseball') > > > > will return all the objects in reverse order. > > Does this only grab the baseball scores? Or grabs all of them and THEN > sorts them by score? > (Just for future reference.) This will grab _all_

Re: QuerySet Question - Selecting a Single Field

2007-06-05 Thread Bryan Veloso
> Score.objects.order_by('-baseball') > > will return all the objects in reverse order. Does this only grab the baseball scores? Or grabs all of them and THEN sorts them by score? (Just for future reference.) > However, it looks like your table is intended to be at least partially > sparse

Re: QuerySet Question - Selecting a Single Field

2007-06-05 Thread Russell Keith-Magee
On 6/6/07, Bryan Veloso <[EMAIL PROTECTED]> wrote: > > Alright, new problem for you guys. Here's an example model in an app > called "scores", which contains all the scores for a particular > player: > > # Baseball > baseball= models.PositiveIntegerField('Baseball Skill > Level',

QuerySet Question - Selecting a Single Field

2007-06-05 Thread Bryan Veloso
Alright, new problem for you guys. Here's an example model in an app called "scores", which contains all the scores for a particular player: # Baseball baseball= models.PositiveIntegerField('Baseball Skill Level', blank=True, null=True, maxlength=4) # Bowling bowling