I haven't played much with annotation/aggregation, so I may be barking up the wrong tree. but on:
https://docs.djangoproject.com/en/1.4/topics/db/aggregation/ I find: "the original results are grouped according to the unique combinations of the fields specified in the values() clause" I take this to mean that all the columns mentioned in the values() method (or all columns if none are mentioned) are forced to be part of grouping. Might this be responsible for the unexpected GROUP_BY column? You have not shown (or I have missed) the query set constructs which you have tried, so I have to guess at what you are passing to value() or even which model (User or Visit) you begin from. (I also don't understand why you have two foreign keys from Visit to User, but that is probably not important.) Bill On Wed, Jul 4, 2012 at 8:15 AM, J. Javier Maestro <jjmaes...@ieee.org> wrote: > On Wed, Jul 4, 2012 at 1:59 PM, J. Javier Maestro <jjmaes...@ieee.org> wrote: >> Hi there! >> >> Thanks a lot for the reply. However, I don't think your solution would >> work in my case, nor it answers the question of whether it can be done >> or why the order_by() adds stuff to the GROUP BY clause when used in >> conjunction with values(). >> >> Let's see: >> >> On Tue, Jul 3, 2012 at 11:08 PM, Bill Freeman <ke1g...@gmail.com> wrote: >>> First, I think that you're going about last_visit in the wrong way. >>> timezone.now() is evaluated once, when the module is imported, >>> rather than when the user visits. DateTimeField's auto_now=True >>> option is tailor made for this kind of situation. >> >> I know about auto_now and, apart from the discussions that can be >> found all over the Internet, is a nice feature... unless you update >> records (like I do). Then, auto_now does nothing since it only affects >> save(). In any case, the default value is actually a leftover from the >> initial implementation, right now is not even needed. > > Bill, > > Re-reading the update() documentation and the way I implemented the > middleware, you are right that auto_now will be the best solution. I > will use save() instead of update() and will get that fixed. > > Thanks a lot for the suggestion! If you have any ideas about the > values() and order_by() issue, I will be happy to hear them! > > Cheers, > > -- > J. Javier Maestro <jjmaes...@ieee.org> > > -- > 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. > -- 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.