Tim,
Here is how I do it with a different query. Using the fetchall() and
getting it into a list works nicely. I know that there should be a
better way to do this so that we're not making a list twice - but this
works:
query = """SELECT b.created_on, SUM(a.vote)
FROM %s a JOIN %s b
ON a.created_on <= b.created_on
ON a.object_id = b.object_id
ON a.content_type_id = b.content_type_id
WHERE a.object_id = %s
AND a.content_type_id = %s
GROUP BY 1""" % (
connection.ops.quote_name(self.model._meta.db_table),
connection.ops.quote_name(self.model._meta.db_table),
obj._get_pk_val(),
ctype.id,
)
cursor = connection.cursor()
cursor.execute(query)
result_list = []
for row in cursor.fetchall():
result_list.append(row)
On Mar 10, 5:19 pm, timc3 <[email protected]> wrote:
> Hi,
>
> I have built my models and so forth, but I have the need to check
> whether the user requesting an instance or set of instances from the
> database has permission to do so.
>
> For this I have a stored procedure (saved procedure) in the database
> that when I give it a user id, it then returns the item if I am
> allowed it. Its a stored procedure because its not possible to do it
> in a SELECT, it potentially would open up a lot of database requests
> if I wanted to do it straight from the App server.
>
> I want to use this in Django, and I thought about using a Manager on
> the model like so:
>
> class MediaItemManager(models.Manager):
> def get_perm(self, *args, **kwargs):
> from django.db import connection
> cursor = connection.cursor()
> cursor.execute("""
> SELECT * FROM permfindernew(2, 132);
> """)
> row = cursor.fetchone()
> return row
>
> Problem comes in that although I return what I want (I will replace 2,
> 132 with the correct args when I am done), its not in a format of a
> queryset or anything else that I can see how I can use.
>
> Another way I could do this is to get the stored procedure to give me
> back a true/false and then do another query if I have got true back.
> This only hits the database twice, but I would like to just return a
> row if possible.
>
> Is there a way to turn what I get back from the database into
> something I can then use in a template:
>
> (132,
> u'Tsunami_by_hokusai_19th_century.jpg',
> u'Tsunami_by_hokusai_19th_century.jpg',
> u'',
> u'',
> datetime.datetime(2009, 2, 17, 16, 54, 38, 892350),
> None,
> u'image-jpg',
> u'c4a6afe0a71e3632',
> 3,
> u'[]',
> 5,
> False,
> False,
> False,
> True,
> True,
> 1,
> u'',
> 1,
> None,
> False,
> 1,
> "'19th':4,9 'hokusai':3,8 'tsunami':1,6 'century.jpg':5,10")
>
> Thanks,
>
> Tim.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---