On Feb 12, 3:29 pm, Karen Tracey <kmtra...@gmail.com> wrote:
> On Thu, Feb 12, 2009 at 10:26 AM, Bobby Roberts <tchend...@gmail.com> wrote:
>
> > My apologies... I didn't see Alex's post. Google some times collapses
> > threads on me. Replacing % with %% seemed to work. It queries the
> > database and returns a dataset like this:
>
> > ((6L, u'WI', u'ST', u'test3', u'test3', u'test3', u'test3', u'test3',
> > u'PR', u',EQ,FL,HU,', u'test3', u',AC,', u'test3', 1, datetime.datetime
> > (2009, 2, 7, 15, 38, 43), u'admin'), (5L, u'FR', u'CH', u'test3',
> > u'test3', u'test3', u'test3', u'test3', u'PR', u',EQ,FL,HU,',
> > u'test3', u',AC,', u'test3', 1, datetime.datetime(2009, 2, 7, 15, 23,
> > 17), None), (4L, u'GR', u'BI', u'test', u'test', u'testusername',
> > u'test', u'test', u'AS', u',EQ,', u'test', u',PR,TX,', u'test', 1,
> > datetime.datetime(2009, 2, 7, 14, 41, 19), None), (3L, u'DR', u'AR',
> > u'sdf', u'sourcelinktest', u'sdf', u'sdf', u'', u'PR', u',FL,HU,',
> > u'sdf', u',SV,TX,', u'sdf', 1, datetime.datetime(2009, 2, 5, 12, 30,
> > 30), None))
>
> > ( that is the value of tms=cursor.fetchall() )
>
> > I'm just not sure how to get the value of tms back up to my template.
> > I'm passing in the data but when i try to do {{tms.title }} for
> > example nothing prints.
>
> I'm confused -- what would you expect tms.title to be? You've pulled (it
> looks like) 4 rows from your DB, each row containing 16(?) fields. Even if
> one of those fields is a title, which of the four titles do you want?
>
> > Forgive me --- i'm a python and django noob.
>
> You've decided to bypass the Django ORM and use raw SQL: that means you are
> going to have to write the code required to take the raw results from the DB
> and turn them into more Python-code friendly objects if you want to use
> constructs like object.title. What you get back from your fetchall call is
> a tuple of tuples. You can iterate through them and build objects from the
> data contained in them, it's not that hard. However, if you are so new to
> Python that it isn't pretty clear to you what you need to do to do that, I'm
> kind of wondering if you really want to be bypassing the ORM as you have
> decided to do. I rather fear you've gone down this path of raw SQL because
> it wasn't immediately clear how to do something (that may well be perfectly
> possible) using the Django ORM and are now just making more work for
> yourself instead of learning how to do whatever it is you need to do through
> the ORM.
>
> However, if you are really sure this is the right path, this thread:
>
> http://groups.google.com/group/django-users/browse_thread/thread/c80e...
>
> discusses some ways of building model objects from your raw sql results that
> you may find helpful.
>
> Karen
Thanks for your informative reply. The reason that I chose raw sql is
that the search form itself has 40 option boxes which control results
in about 7 fields. I was looking at the filtering mechanism for
django db calls and it really wouldn't apply due to the way that the
database is structured (ie an IN filter wouldn't work for some of
these things.). That url you referred to is just what i'm looking
for. I'm an ASP programmer making the transition away from the dark
side and still have wobbly python legs so i'm not always 100% sure
what to search for. Thanks again.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---