Re: Django and a basic SQL join

2009-05-08 Thread Malcolm Tredinnick
On Wed, 2009-05-06 at 13:14 -0700, jrs_66 wrote: > Thanks! This is a great starting point. My real queryset requires me > to go a few joins deeper, however. I will try nesting loops to get > there, but this seems frightfully like querying in a loop (maybe I'm > wrong, I'll check the end query t

Re: Django and a basic SQL join

2009-05-06 Thread jrs_66
Phil, Thanks for the pointers. I guess my thinking on this is that if someone feels a question is too trite to warrant and answer, they shouldn't answer. I don't think this group is called 'advanced django users', thus I don't really feel bad for posting 'newbie' questions. I appreciate all ans

Re: Django and a basic SQL join

2009-05-06 Thread jrs_66
Thanks! This is a great starting point. My real queryset requires me to go a few joins deeper, however. I will try nesting loops to get there, but this seems frightfully like querying in a loop (maybe I'm wrong, I'll check the end query to find out). It also seems like a frightening amount of

Re: Django and a basic SQL join

2009-05-06 Thread Alex Koshelev
On Wed, May 6, 2009 at 8:48 PM, jrs_66 wrote: > > Hi, > > I have 2 models... > [skip] > > e = FlattenedCategory.objects.select_related('category').filter > (member_of_category=15) > > which works... This, however, doesn't > > e = e.category > > How do I access the related records from the Cat

Re: Django and a basic SQL join

2009-05-06 Thread Phil Mocek
On Wed, May 06, 2009 at 10:17:29AM -0700, jrs_66 wrote: > This is definitely the most angry forum I've ever seen... the > kicker is that the anger is almost always coming from the people > associated with the django project... hmmm.. In your previous thread, someone from the Django project helpfu

Re: Django and a basic SQL join

2009-05-06 Thread Clément Nodet
> > In your case e is a QuerySet, with multiple FlattenedCategory objects. > > So the proper code would be to loop through them: > > {{{ > for fc in e: >     fc.category_set > }}} > Indeed, but category being a ForeignKey field, {{{ for fc in e: fc.category }}} will work here. -- Clément --

Re: Django and a basic SQL join

2009-05-06 Thread George Song
In your case e is a QuerySet, with multiple FlattenedCategory objects. So the proper code would be to loop through them: {{{ for fc in e: fc.category_set }}} On 5/6/2009 10:17 AM, jrs_66 wrote: > No... 'QuerySet' object has no > attribute 'category_set' > > George, > > I have read the

Re: Django and a basic SQL join

2009-05-06 Thread mamco
jrs_66: you may find some comfort in the http://ubuntuforums.org/forumdisplay.php?f=39 forum - not specific to django, but quite a friendly bunch and lots of python folks willing to assist with the learning process. tag your posts with 'django' On May 6, 2:17 pm, jrs_66 wrote: > > This is defi

Re: Django and a basic SQL join

2009-05-06 Thread jrs_66
No... 'QuerySet' object has no attribute 'category_set' George, I have read the docs... MANY times... from the docs... 'Django also creates API accessors for the "other" side of the relationship -- the link from the related model to the model that defines the relationship. For example, a Blog

Re: Django and a basic SQL join

2009-05-06 Thread George Song
On 5/6/2009 9:48 AM, jrs_66 wrote: > I have 2 models... > > class Category(models.Model): > name = models.CharField(max_length=255) > parent = models.ForeignKey('self', null=True) > has_children = models.BooleanField(default=False) > language = models.ForeignKey(Language, null=Fal

Django and a basic SQL join

2009-05-06 Thread jrs_66
Hi, I have 2 models... class Category(models.Model): name = models.CharField(max_length=255) parent = models.ForeignKey('self', null=True) has_children = models.BooleanField(default=False) language = models.ForeignKey(Language, null=False, default=1) active = models.BooleanFi

Re: SQL Join in Django

2008-11-07 Thread Hossein
Thanks for your help. I am so close to what I want. The output that I want is an XML file. So I try: reporter = Reporter.objects.get(id=10) arts = reporter.article_set.all() xmlout = serialize('xml',arts,fields=('date','reporter.name')) However, it writes date but it does not w

Re: SQL Join in Django

2008-11-07 Thread Tim Chase
> I tried your suggested solution and instead of printing the result I > use Django serializer to create an XML file. But it seems that > something is taking too > long and my browser just stalls. Is it because of select_related() > method? I have about 200 articles per each reporter. Another pos

Re: SQL Join in Django

2008-11-07 Thread Hossein
Many thanks tim for your quick reply. You are right I meant inner join not cart product. I tried your suggested solution and instead of printing the result I use Django serializer to create an XML file. But it seems that something is taking too long and my browser just stalls. Is it because of sel

Re: SQL Join in Django

2008-11-07 Thread Tim Chase
> class Reporter() > id primary key > name > e-mail > ... > > class Article() > reporter = model.ForeignKey(reporter) > date > ... > > Now I want to implement the following SQL statement in Django: > > select name,e-mail,date from Reporter,Article where reporter

SQL Join in Django

2008-11-07 Thread Hossein
Hi, I am a newbie and am trying to select fields from two table related to each other using a foreign key: class Reporter() id primary key name e-mail ... class Article() reporter = model.ForeignKey(reporter) date ... Now I want to implement the following SQL s

Re: SQL join--why not grab all columns?

2008-09-17 Thread Chris Stromberger
On Wed, Sep 17, 2008 at 7:40 PM, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > > > On Wed, 2008-09-17 at 19:30 -0500, Chris Stromberger wrote: > > Disclaimer: Django newbie here. > > > > I have a join type of model access in one of my views like so: > > > > recent_staff_reviews = > > StaffReview

Re: SQL join--why not grab all columns?

2008-09-17 Thread Malcolm Tredinnick
On Wed, 2008-09-17 at 19:30 -0500, Chris Stromberger wrote: > Disclaimer: Django newbie here. > > I have a join type of model access in one of my views like so: > > recent_staff_reviews = > StaffReview.objects.order_by('-last_update').filter(enabled = > True).filter(restaurant__enabled = True)[

SQL join--why not grab all columns?

2008-09-17 Thread Chris Stromberger
Disclaimer: Django newbie here. I have a join type of model access in one of my views like so: recent_staff_reviews = StaffReview.objects.order_by('-last_update').filter(enabled = True).filter(restaurant__enabled = True)[:4] where the StaffReview model has a foreign key to the Restaurant model.

Re: SQL Join

2008-02-13 Thread Nicolas Steinmetz
Gus a écrit : > any help would be much appreciated Maybe this thread will help you (my issue was quite similar) Nicolas --~--~-~--~~~---~--~~ You received this message because y

Re: SQL Join

2008-02-13 Thread J. Clifford Dyer
The type field on Membership rules out m2m. There's a patch in the works (6095) to address this, and it could use testing, if you'd like to try it out. Alternatively, set up a many to one from membership to user, and from membership to group, and call the backrefs "groups" and "users" respective

Re: SQL Join

2008-02-12 Thread Alex Ezell
This doesn't answer your question directly, but wouldn't many-to-many fields help a bit here? http://www.djangoproject.com/documentation/model-api/#many-to-many-relationships Sorry if you've already thought about this and dismissed it. /alex On Feb 12, 2008 11:41 PM, Gus <[EMAIL PROTECTED]> wr

SQL Join

2008-02-12 Thread Gus
Hi all, I have something like: Class User id Class Group id Class Membership id group fk user fk type char1 Class Message id group fk user fk I'm a little confused about how to do this join from the django db api: select message.* from message, membership where message.group_id = m