On Apr 3, 11:27 am, KasunLak <kasun.lakpriy...@gmail.com> wrote:
> Hi,
>
> No, sorry for not giving more details. What I am asking is once we
> syncdb the generated scripts (create table). Can we see the method
> implementation of database access api?
>
> For example: If we have created and deployed a model called Poll
> (tutorial example in django site)
>
> p = Poll.objects.get(pk=1).
>
> Can we see the implementation of this get(pk) method? I think these
> are some objects in the database, just wonder this is possible?

If you mean what SQL it generates there are two methods inbuilt to
django. If you have settings.DEBUG = True, you can use:
> p = Poll.objects.get(pk=1).
> django.db import connection
> print connection.queries[-1]

Another option:
> print Poll.objects.filter(pk=1).query
This one does work only for QuerySet, so if the method you are
interested in executes the query immediately (like .get()), then you
can't use this method.

Neither of the above will give you correctly quoted querystring, as
that is simply not available to Django. The database backend libraries
do the quoting, and Django can't get the quoted query string back from
the libraries.

If you want to see the Python code implementation, look at django/db/
models/query.py, which uses django/db/models/sql/query.py. Be warned:
the sql/query.py will take some time to understand, it is one of the
most complex pieces of code in Django.

 - Anssi

-- 
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.

Reply via email to