Wednesday, February 1, 2012

Re: about QuerySet

On Wednesday, 1 February 2012 08:34:14 UTC, akaariai wrote:
On Feb 1, 9:36 am, newme <dlli...@gmail.com> wrote:
> do you mean that queryset will query database every time i call
> user[0]?

Yes. That is exactly what happens:
In [7]: qs[0]
Out[7]: <OrganisaatioOsa: THL - Terveyden ja hyvinvoinnin laitos>
In [9]: print connection.queries
[{'time': '0.011', 'sql': 'SELECT ... FROM "organisaatio_osa" LIMIT
1'}]

In [10]: qs[0]
Out[10]: <OrganisaatioOsa: THL - Terveyden ja hyvinvoinnin laitos>
In [11]: print connection.queries
[{'time': '0.011', 'sql': 'SELECT ... FROM "organisaatio_osa" LIMIT
1'},
 {'time': '0.001', 'sql': 'SELECT ... FROM "organisaatio_osa" LIMIT
1'}]

If you do not want this to happen, you can evaluate your queryset into
a list first by:
objlist = list(qs[0:wanted_limit])
and now objlist is just a regular Python list.

The lazy evaluation of querysets can be a little surprising sometimes.
Using django-debug-toolbar or just settings.DEBUG = True, and then
print connection.queries is recommended :)

 - Anssi

Slight clarification: the slicing will only trigger a db call if the queryset has not been evaluated. Converting it to a list is one way of doing that, but if you iterate the queryset in any way it will populate the internal cache and not call the database on subsequent slices.
--
DR.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/0c4swAOEgygJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Django admin set column width in change list

Hello ,

Newbie question here : I need to change the column width in django-
admin change list.
Can I do it in admin.ModelAdmin or models.Model.

Thanks,
Svilen.

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: about QuerySet

On Feb 1, 9:36 am, newme <dllizh...@gmail.com> wrote:
> do you mean that queryset will query database every time i call
> user[0]?

Yes. That is exactly what happens:
In [7]: qs[0]
Out[7]: <OrganisaatioOsa: THL - Terveyden ja hyvinvoinnin laitos>
In [9]: print connection.queries
[{'time': '0.011', 'sql': 'SELECT ... FROM "organisaatio_osa" LIMIT
1'}]

In [10]: qs[0]
Out[10]: <OrganisaatioOsa: THL - Terveyden ja hyvinvoinnin laitos>
In [11]: print connection.queries
[{'time': '0.011', 'sql': 'SELECT ... FROM "organisaatio_osa" LIMIT
1'},
{'time': '0.001', 'sql': 'SELECT ... FROM "organisaatio_osa" LIMIT
1'}]

If you do not want this to happen, you can evaluate your queryset into
a list first by:
objlist = list(qs[0:wanted_limit])
and now objlist is just a regular Python list.

The lazy evaluation of querysets can be a little surprising sometimes.
Using django-debug-toolbar or just settings.DEBUG = True, and then
print connection.queries is recommended :)

- 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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Building authentication backend

Hello.

A very simple question.

I am building an authentication back end to support TWO passwords.
This requires me to add an extra table to store the secondary password
plus a ForeignKey to User.

The confusing part is, how I make Django automatically create the
needed table when SyncDB is run?
And how do I make this new table show up in the Admin-interface as
well?

Thanks.

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

How to get unique results from fields in sliced QuerySet ?

Hi all,

I have models called Books.

To get unique results from Books, usually I use order_by().values('field').
For example, I want unique writter :

Books.objects.filter(created__year=2012).order_by('writter').values('writter').distinct()

But, how to get unique results from sliced Queryset ?

books = Books.objects.filter(created__year=2012)[:5]

# Doesnt' works , Can reorder a query once  a slice has been taken
unique = books
.order_by('writter').values('writter').distinct()

# Doesnt' works, it will show all queryset (not unique)
unique = books.values('writter').distinct()

# Also doesn't works
unique = books.annotate().values('writter').distinct()
unique = books.values('writter').distinct().annotate().

Anyone have this problem ? Is it possible to get unique results from sliced queryset ?


Thanks

Bashlook


Re: Dynamic runtime modeling: which is the best choice?

>         This sounds more like a need for shapefile translators (codecs, if
> you will)... On input you'd convert the contents into a common database
> format; reverse the process on output.

What is a "common database format"? If a shape file has 5 fields and
another one 10 (and I dont' know the fields name!) how can I
generalize this situation before getting those files?

>         IOWs, my view is that you should be storing the "shape" and not the
> "file".

What do yuo mean? LayerMapping is not the right way?

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Inherited manytomany field not showing up in django shell

I am working on blog application. I have made class "GenericBlog",
which I am inheriting to a class Blog.There is a manytomany field in
the GenericBlog class called "sites".

The problem in this that when I try to create an object of "Blog", in
the django shell, it gives an error "sites si an invalid keyword".

I would be very grateful, if you can help me with a possible solution
to this problem


Kabir

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.