Re: ORM Question

2014-04-03 Thread Bill Freeman
>From the lack of other folks jumping in saying "do it this way", I'm going to guess that this is a hard problem. I am not a database heavyweight. (IANADbH) I especially don't know about limitations of MySQL. It seems that you need to calculate a maximum size of Llama objects, but separately

Re: ORM Question

2014-04-02 Thread Justin Holmes
I think you misunderstand: I am not actually tracking llama herds. :-) This is just example code; I haven't actually tested it in the way that you suggest. The problem isn't with this code in particular, it's with this concept in general. This is a question I have had again and again in the

Re: ORM Question

2014-04-02 Thread Bill Freeman
My point was that annotate might work after the other problems were fixed. Have you re-tested since? If your annotate still doesn't work then perhaps someone with more annotate experience than I will comment. On Wed, Apr 2, 2014 at 12:04 PM, Justin Holmes wrote: > No

Re: ORM Question

2014-04-02 Thread Justin Holmes
No no, the annotate doesn't work - that's the whole reason for my question. See, the annotate doesn't associate instances with the annotated attribute, it associated results. (BTW, good looking out - I have once again fixed the SO question :-)) On Wed, Apr 2, 2014 at 10:17 AM, Bill Freeman

Re: ORM Question

2014-04-02 Thread Bill Freeman
1. You now have a foreign key to Herd, but you don't have a model by that name. It's called LlamaHerd. 2. I was misinterpreting what you wanted (couldn't get past the lack of a relationship while reading0. Once the relationship is fixed, your original annotate might work. On Tue, Apr 1,

Re: ORM Question

2014-04-01 Thread Justin Holmes
You say "use the reverse relation manager in LlamaHerd to build up your annotation," but that answer the question. How can I sort LlamaHerd objects by the DOB of their largest llama? On Tue, Apr 1, 2014 at 6:13 PM, Justin Holmes wrote: > Yes, absolutely - my bad. I

Re: ORM Question

2014-04-01 Thread Justin Holmes
Yes, absolutely - my bad. I have updated to SO question. I meant the models to look like: class LlamaHerd(models.Model): shepherd = ForeignKey(User) class Llama(models.Model): size = FloatField() dob = FloatField herd = ForeignKey(Herd, related_name="llamas") On Tue, Apr 1,

Re: ORM Question

2014-04-01 Thread Bill Freeman
Aren't you missing a ForeignKey relationship to tell which LlamaHerd a Llama belongs to? Then you would use the reverse relation manager in LlamaHerd to build up your annotation. On Tue, Apr 1, 2014 at 5:52 PM, Justin Holmes wrote: > I have come across this problem in

ORM Question

2014-04-01 Thread Justin Holmes
I have come across this problem in several Django projects, but only just now worked it out in my head enough to make it a cognizable question. I have also posted it on StackOverflow, here:

Re: Django ORM question about lookups that span relationships

2011-04-26 Thread Carsten Fuchs
First of all, many thanks to everyone who replied in this thread, your posts were very interesting and helpful! On 24.04.2011 07:35, Alexander Schepanovski wrote: You can, with a subrequest: Blog.objects.filter(pk__in=Entry.objects.filter(pub_date__lte=date(2011, 4, 1),

Re: Django ORM question about lookups that span relationships

2011-04-23 Thread Alexander Schepanovski
> Yes, but while raw() has its uses, it's an interesting question: Is > there a way to do this with the Django ORM or not? It's always hard to > write raw queries in a database independent way, so there are good cases > where you want to avoid raw(). You can, with a subrequest:

Re: Django ORM question about lookups that span relationships

2011-04-22 Thread Michael Radziej
On Fri, 22 Apr 2011 13:08:17 -0500, Jacob Kaplan-Moss wrote: > Blog.objects.raw('''SELECT * FROM blog Hey, that's cheating :-) > No, really -- if I was faced with a query, like this, that was easier > to express with SQL, I'd reach for `raw()` long before trying to >

Re: Django ORM question about lookups that span relationships

2011-04-22 Thread Jacob Kaplan-Moss
On Fri, Apr 22, 2011 at 5:36 AM, Michael Radziej wrote: > In SQL, it's something along > > SELECT ... FROM blog > JOIN entry e1 on e1.entry_id = blog.id >     AND e1.pub_date <= ... >     AND e1.headline LIKE "%Easter%" >     AND NOT exists >     ( SELECT id from entry e2 >      

Re: Django ORM question about lookups that span relationships

2011-04-22 Thread Michael Radziej
On Fri, 22 Apr 2011 07:02:22 +0300, Oleg Lomaka wrote: > Blog.objects.filter(entry__pub_date__lte=date(2011, 4, 1), > entry__headline__contains='Easter > ').latest('pub_date') > > Or > > Blog.objects.filter(entry__pub_date__lte=date(2011, 4, 1),

Re: Django ORM question about lookups that span relationships

2011-04-21 Thread Oleg Lomaka
Blog.objects.filter(entry__pub_date__lte=date(2011, 4, 1), entry__headline__contains='Easter ').latest('pub_date') Or Blog.objects.filter(entry__pub_date__lte=date(2011, 4, 1), entry__headline__contains='Easter ').order_by('-pub_date')[0] On

Django ORM question about lookups that span relationships

2011-04-21 Thread Carsten Fuchs
Hi all, I'm currently reading . What I seem to understand is how I can find all blogs that have entries that - where published *sometime* before or at April 1st, - and have the word

Re: ORM question

2008-06-07 Thread Dan W.
Thanks, guys. Those are just the pointers I needed. Dan On Fri, Jun 6, 2008 at 5:02 PM, James Bennett <[EMAIL PROTECTED]> wrote: > > On Fri, Jun 6, 2008 at 6:57 PM, Dan W. <[EMAIL PROTECTED]> wrote: > > I'm pretty new to django and so far so good except for one thing. When I > > fetch model

Re: ORM question

2008-06-06 Thread [EMAIL PROTECTED]
Managers are never iterables, for example you can't do: for model in Model.objects: so you would do: for model in Model.objects.all(): the same concept applies to related managers. On Jun 6, 6:57 pm, "Dan W." <[EMAIL PROTECTED]> wrote: > I'm pretty new to django and so far so good

Re: ORM question

2008-06-06 Thread James Bennett
On Fri, Jun 6, 2008 at 6:57 PM, Dan W. <[EMAIL PROTECTED]> wrote: > I'm pretty new to django and so far so good except for one thing. When I > fetch model objects, their related objects are showing up as RelatedManager > and ManyRelatedManager objects intead of the types I created and modified in

ORM question

2008-06-06 Thread Dan W.
I'm pretty new to django and so far so good except for one thing. When I fetch model objects, their related objects are showing up as RelatedManager and ManyRelatedManager objects intead of the types I created and modified in my model. Consequently if I try to iterate over them or access their

Re: Stand-alone Django ORM question

2007-08-30 Thread Abhijit Choudhury
<[EMAIL PROTECTED]> To: Django users <django-users@googlegroups.com> Sent: Thursday, August 30, 2007 11:47:31 AM Subject: Re: Stand-alone Django ORM question Define app_name in Meta nested-class: class Meta: app_name

Re: Stand-alone Django ORM question

2007-08-30 Thread daev
Define app_name in Meta nested-class: class Meta: app_name = "some_name" --~--~-~--~~~---~--~~ 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

Re: Stand-alone Django ORM question

2007-08-30 Thread canen
I'm not sure but maybe you need the INSTALLED_APPS setting. On Aug 30, 10:21 am, ceeed <[EMAIL PROTECTED]> wrote: > Hello, > I am a Django newbie and trying to learn it. > > As a project, I am trying to use the Django ORM in a stand-alone sense > (i.e., without creating a project and app). I am

Stand-alone Django ORM question

2007-08-30 Thread ceeed
Hello, I am a Django newbie and trying to learn it. As a project, I am trying to use the Django ORM in a stand-alone sense (i.e., without creating a project and app). I am using SQLITE and have defined the models. I would like to a) create the table in the database based on my models, b)