Re: How to annotate many values in one queryset

2014-08-18 Thread 9devmail
> As an aside, this can probably be written as: > > current_user_vote = item.vote_set.filter(user=request.user) > > > > > I tried to use annotate() two times, however it filtered out everything > > except items current user voted on. > > Just use it once. > Thank you for answer, however

How to annotate many values in one queryset

2014-08-18 Thread 9devmail
Is it possible to annotate two different values to one QuerySet? Example queryset: Item.objects.annotate(score=Count('votes')) I would like every item in the above QuerySet to contain the following field: current_user_vote = Vote.objects.filter(user=request.user).filter(item=item) I tried to

Re: Efficient way to perform many queries

2014-08-17 Thread 9devmail
Thank you, it works perfectly :) -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to

Re: Efficient way to perform many queries

2014-08-16 Thread 9devmail
prefetch_related() works great. How about prefetching some computed value instead of records? {% for item in items %} {{ item.name }} {{ item.score }} {% endfor %} I want to prefetch 'score' for every item, where 'score' would be equivalent to: score = Votes.objects.all().count() -

Re: Efficient way to perform many queries

2014-08-15 Thread 9devmail
Thank you. What if I'm using GenericForeignKey in Tags model? Can I still use it? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googl

Efficient way to perform many queries

2014-08-15 Thread 9devmail
I am writing application similar to django-taggit and I was wondering about its performance. Example for list of items: {% for item in items %} {{ item.name }} {% for tag in item.tags.all %} {{ tag }} {% endfor %} {% endfor %} Abov

Re: How to decompose URL into model and parameters

2014-08-14 Thread 9devmail
Yes, I figured it out. Thank you. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to

Re: How to decompose URL into model and parameters

2014-08-14 Thread 9devmail
Line match = urlresolvers.resolve(urlsplit(url).path) stops executing the script and redirects me to given URL. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to

How to decompose URL into model and parameters

2014-08-14 Thread 9devmail
I want to parse an application URL just like Django does. url = 'http://www.example.com/path/to/myview/123' view, params = decompose(url) # now view="MyView", params=('123',) How can it be done? -- You received this message because you are subscribed to the Google Groups "Django users" group.

How to sort by many custom methods in Django Admin

2014-07-10 Thread 9devmail
I want to be able to sort by several custom methods in Django Admin. This question on StackOverflow provides solution for one method only. I tried to modify it: from

Re: How to filter objects by values of foreign objects in Django admin

2014-07-07 Thread 9devmail
No, it does not. I cannot pass any parameters to this function, because it is being invoked automatically by the admin. class MyAdmin(admin.ModelAdmin): list_display = ['num_of_trans'] How can I pass any arguments to it? Please, read my question carefully. -- You received this message bec

Re: How to filter objects by values of foreign objects in Django admin

2014-07-07 Thread 9devmail
Thank you, but I think you misunderstood. I do not want to filter Product objects. I want to filter Transaction objects. Please, take a look at provided example. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group a

Re: How to filter objects by values of foreign objects in Django admin

2014-07-07 Thread 9devmail
Thanks for pointing it out. However, my question is about a different issue. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegrou

How to filter objects by values of foreign objects in Django admin

2014-07-07 Thread 9devmail
There are tables Product and Transaction. In Product admin there is a field that shows how many transactions have been created with this product. Now, I want to filter the period of time in which these transactions were created. For example, there was 30 transactions in the last week, but 100

How to create a custom admin panel for many models

2014-07-04 Thread 9devmail
I want to create a custom ModelAdmin, but for a mix of models, not just one. I have two example models: class Article(models.Model): author = models.GenericIPAddressField() # ... class Comment(models.Model): author = models.GenericIPAddressField() # ... Now I want to be able t

How to use CreateView with crispy-forms

2014-05-28 Thread 9devmail
I want to use CreateView along with crispy-forms generated layout. However, it seems that everything I pass to *self.helper* in *forms.py* is ignored. Form renders nicely, but only with fields generated by CreateView - all fields passed to *Layout* are missing. My views.py > class MyView(Cr