Re: group by "project"

2023-05-24 Thread 'Mohamed Yahiya Shajahan' via Django users
[ { "project": 1, "date": "2023-05-22", "count": 1 }, { "project": 1, "date": "2023-05-27", "count": 1 } ] throws this response. i want group by project def list(self, request, *args, **kwargs): project_id = self.reques

Re: group by "project"

2023-05-24 Thread Helly Modi
TRY THIS from django.db.models import Count def list(self, request, *args, **kwargs): project_id = self.request.query_params.get('project_id') if project_id: queryset = RegistrationDatesSlots.objects.values('project', 'date').annotate(count=Count('project')).filter(project=project

Re: group by "project"

2023-05-24 Thread Muhammad Juwaini Abdul Rahman
Do you realize what 'Count' do? On Thu, 25 May 2023 at 09:20, 'Mohamed Yahiya Shajahan' via Django users < django-users@googlegroups.com> wrote: > def list(self, request, *args, **kwargs): > project_id = self.request.query_params.get('project_id') > if project_id: >

Re: GROUP BY

2018-08-14 Thread Mikkel Kromann
t; > *From:* django...@googlegroups.com [mailto: > django...@googlegroups.com ] *On Behalf Of *Mikkel Kromann > *Sent:* Tuesday, August 14, 2018 1:27 PM > *To:* Django users > *Subject:* Re: GROUP BY > > > > > > @galan: > > the __ is reference to a for

RE: GROUP BY

2018-08-14 Thread Matthew Pava
users Subject: Re: GROUP BY @galan: the __ is reference to a foreign key name for market, and __year is a function extracting the year from the datefield. Sorry for not posting the model, that would have helped avoiding this. @matthew Yes, that's right. That was one error down. The following

Re: GROUP BY

2018-08-14 Thread Mikkel Kromann
irsdag den 14. august 2018 kl. 15.28.01 UTC+2 skrev Matthew Pava: > > Ah, the error has the answer. contract_row is a dictionary, so you need > to access it as if it were a dictionary. > > contract_sum = contract_row['contracted'] > > > > *From:* django...@googlegroups

Re: GROUP BY

2018-08-14 Thread Mikkel Kromann
ct_row['contracted'] > > > > *From:* django...@googlegroups.com [mailto: > django...@googlegroups.com ] *On Behalf Of *Mikkel Kromann > *Sent:* Monday, August 13, 2018 11:51 PM > *To:* Django users > *Subject:* Re: GROUP BY > > > > > > Th

RE: GROUP BY

2018-08-14 Thread Matthew Pava
2018 11:51 PM To: Django users Subject: Re: GROUP BY Thanks. But strange - exactly same error: 'dict' object has no attribute 'contracted' contract_query = (Project.objects.all() .filter(department=department_id)

Re: GROUP BY

2018-08-13 Thread Gagan Kalia
Try not to use _ (underscore) character as prefix or postfix to any user defined variable or db column. Its not recommended in django. On Tue 14 Aug, 2018, 1:52 AM Mikkel Kromann, wrote: > I'm trying to sum the field "ownProduction", grouping it by the foreign > key "market" (using the market's

Re: GROUP BY

2018-08-13 Thread Mikkel Kromann
Thanks. But strange - exactly same error: 'dict' object has no attribute 'contracted' contract_query = (Project.objects.all() .filter(department=department_id) .filter(datePipeline__year=year)

RE: GROUP BY

2018-08-13 Thread Matthew Pava
You need to include “ownProduction” in your values list prior to the annotation. From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On Behalf Of Mikkel Kromann Sent: Monday, August 13, 2018 3:22 PM To: Django users Subject: GROUP BY I'm trying to sum the field "ownProduc

Re: GROUP BY behavior change in Django 2.0 with annotate/extra

2018-03-12 Thread Tim Graham
I'd use git bisect to find the commit where the behavior changed in Django. That will likely yield some insight. https://docs.djangoproject.com/en/dev/internals/contributing/triaging-tickets/#bisecting-a-regression On Friday, March 9, 2018 at 5:39:43 PM UTC-5, Michael Soderstrom wrote: > > In a

Re: group by 3 fields

2017-03-01 Thread marcin . j . nowak
On Wednesday, March 1, 2017 at 2:09:06 PM UTC+1, larry@gmail.com wrote: > > > I had thought of using a view, but that would have been a lot of > overhead on such a large table. I also considered adding a column and > running a one time script to update the existing rows, and modifying > th

Re: group by 3 fields

2017-03-01 Thread Larry Martell
On Wed, Mar 1, 2017 at 8:01 AM, wrote: > >> >> As is so often the case, the requirements changed. Now what I had to >> do, if I was doing it in SQL would have been: >> >> (CASE >> WHEN TRIM(IFNULL(roiname, '')) IN ('', 'None') THEN CONCAT_WS('.', >> CONVERT(roi_type_id, CHAR), roi_id) >> WHEN C

Re: group by 3 fields

2017-03-01 Thread marcin . j . nowak
> > As is so often the case, the requirements changed. Now what I had to > do, if I was doing it in SQL would have been: > > (CASE > WHEN TRIM(IFNULL(roiname, '')) IN ('', 'None') THEN CONCAT_WS('.', > CONVERT(roi_type_id, CHAR), roi_id) > WHEN CONCAT_WS('.', CONVERT(roi_type_id, CHAR), ro

Re: group by 3 fields

2017-03-01 Thread Larry Martell
On Mon, Feb 27, 2017 at 3:41 AM, wrote: > > > On Monday, February 27, 2017 at 3:52:38 AM UTC+1, larry@gmail.com wrote: >> >> [SQL] That is a language I >> have worked in for over 20 years, and when I see a querying need that >> is how I think, and then I see how can I do that with the ORM. >

Re: group by 3 fields

2017-02-27 Thread marcin . j . nowak
On Monday, February 27, 2017 at 3:52:38 AM UTC+1, larry@gmail.com wrote: > > [SQL] That is a language I > have worked in for over 20 years, and when I see a querying need that > is how I think, and then I see how can I do that with the ORM. > So I shouldn't give advices for you. We have s

Re: group by 3 fields

2017-02-26 Thread Larry Martell
On Sun, Feb 26, 2017 at 5:05 PM, wrote: > > > On Sunday, February 26, 2017 at 12:55:17 PM UTC+1, Daniel Roseman wrote: >> >> >> You should explain what you want to achieve. Grouping is pointless on its >> own. In any case, when working with an ORM like Django's it is generally not >> helpful to t

Re: group by 3 fields

2017-02-26 Thread Larry Martell
On Sun, Feb 26, 2017 at 6:55 AM, Daniel Roseman wrote: > On Sunday, 26 February 2017 11:11:39 UTC, larry@gmail.com wrote: >> >> Order by is not the same as group by. Group by does aggregation >> > > You should explain what you want to achieve. Grouping is pointless on its > own. In any case, w

Re: group by 3 fields

2017-02-26 Thread marcin . j . nowak
On Sunday, February 26, 2017 at 12:55:17 PM UTC+1, Daniel Roseman wrote: > > > You should explain what you want to achieve. Grouping is pointless on its > own. In any case, when working with an ORM like Django's it is generally > not helpful to think in terms of SQL. > -- > DR. > Also forget

Re: group by 3 fields

2017-02-26 Thread Daniel Roseman
On Sunday, 26 February 2017 11:11:39 UTC, larry@gmail.com wrote: > > Order by is not the same as group by. Group by does aggregation > > You should explain what you want to achieve. Grouping is pointless on its own. In any case, when working with an ORM like Django's it is generally not help

Re: group by 3 fields

2017-02-26 Thread Larry Martell
Order by is not the same as group by. Group by does aggregation On Sun, Feb 26, 2017 at 5:30 AM chris rose wrote: > there is a model meta option called ordering. you can specify a list of > fields to order by > > docs found at: > https://docs.djangoproject.com/en/1.10/ref/models/options/#orderin

Re: group by 3 fields

2017-02-26 Thread chris rose
there is a model meta option called ordering. you can specify a list of fields to order by docs found at: https://docs.djangoproject.com/en/1.10/ref/models/options/#ordering i have only used this in the admin -- You received this message because you are subscribed to the Google Groups "Djang

Re: GROUP BY without using aggregate function

2016-03-03 Thread marcin . j . nowak
On Thursday, March 3, 2016 at 2:28:58 PM UTC+1, Michal Petrucha wrote: > > > Merely based on your vague description, it seems to me that this is > one of the cases where you might be better off writing your SQL query > manually. > > Narrowing results by `filter()` is very handy, in contrast to

Re: GROUP BY without using aggregate function

2016-03-03 Thread Michal Petrucha
On Wed, Mar 02, 2016 at 09:21:03AM -0800, marcin.j.no...@gmail.com wrote: > > > On Wednesday, March 2, 2016 at 6:11:32 PM UTC+1, Dan Tagg wrote: > > > > if your aren't counting or averaging then why are you grouping? > > > > > > > To fast find distinct values within big dataset - some queries on

Re: GROUP BY without using aggregate function

2016-03-02 Thread marcin . j . nowak
On Wednesday, March 2, 2016 at 6:11:32 PM UTC+1, Dan Tagg wrote: > > if your aren't counting or averaging then why are you grouping? > > > To fast find distinct values within big dataset - some queries on some engines may be faster when using grouping. It was known technique years ago and I'm s

Re: GROUP BY without using aggregate function

2016-03-02 Thread Dan Tagg
if your aren't counting or averaging then why are you grouping? D On 2 March 2016 at 17:06, wrote: > Hello, > > I would like to query database with Django ORM and add GROUP BY clause > without including unnecessary counting, avg, etc. > I can force/hack queryset by settting qs.query.group_by=['

Re: Group by using DJango ORM

2013-09-19 Thread Russell Keith-Magee
On Fri, Sep 20, 2013 at 7:34 AM, Nicolas Mendoza wrote: > Actually what's the best way for do a group by using django ORM? > > I know workarounds like combinate "values" with "Anotate", etc. but I > wil like know your favorite workaround without rawSQL and not manager > based , only Django ORM ;-

Re: group by and retrieve to template date from foreinKey

2011-07-15 Thread nicolas HERSOG
Oh sorry, I knew that my sql query was naive, but my question was really about how to use group by and retrieve data throug my template :/ I'm really sorry for waste your time with stupid sql. Nevertheless a great thank you for your help. I'm going to do like you say and in few times, try to chan

Re: group by and retrieve to template date from foreinKey

2011-07-15 Thread bruno desthuilliers
On Jul 15, 2:53 pm, nicolas HERSOG wrote: > Of course, and thanks for your help :) > > This is the rows of my first table Video : > id | name | category_id | date > 1 | vids1 | 1 | dd-jj- > 2 | vids2 | 1 | dd-jj- > 3 | vids3 | 1 | dd-jj- > 4 | vids4 | 2 | dd-jj- > 5 | vids5 | 2 | d

Re: group by and retrieve to template date from foreinKey

2011-07-15 Thread nicolas HERSOG
Of course, and thanks for your help :) This is the rows of my first table Video : id | name | category_id | date 1 | vids1 | 1 | dd-jj- 2 | vids2 | 1 | dd-jj- 3 | vids3 | 1 | dd-jj- 4 | vids4 | 2 | dd-jj- 5 | vids5 | 2 | dd-jj- 6 | vids6 | 3 | dd-jj- and here the rows of t

Re: group by and retrieve to template date from foreinKey

2011-07-15 Thread bruno desthuilliers
On Jul 15, 10:13 am, Suprnaturall wrote: > Hi dear django users :) > > I m facing a stupid problem. > Here is my models.py : > > class Video(models.Model): >     (...) >     category = models.ForeignKey('Category') >    (...) > > class Category(models.Model): >     name = models.CharField(max_leng

Re: group by and retrieve to template date from foreinKey

2011-07-15 Thread Venkatraman S
concise reply : I would strongly suggest you to have a look at django-taggit. OTOH, use django-debug-toolbar to diagnose the sql that is being fired. -V -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django

Re: Group by date: Annotate & Aggregate Query

2011-03-24 Thread Casey Greene
Aggregation for dates is a feature that has a trac ticket: http://code.djangoproject.com/ticket/10302 One option would be to implement this (it's also listed for google SoC 2011 so maybe someone else will do it http://code.djangoproject.com/wiki/SummerOfCode2011#Improveannotationandaggregation

Re: GROUP BY fields appearance, bug or feature?

2011-01-16 Thread Jari Pennanen
Here is my problem as using powerful raw, User.objects.raw('SELECT usr.*, em.added as latest_email_added, em.success as latest_email_success, em.subject as latest_email_subject FROM auth_user AS usr LEFT JOIN dmusic_useremail as em ON em.user_id = usr.id GROUP BY usr.id HAVING Max(em.added)') Tha

Re: GROUP BY fields appearance, bug or feature?

2011-01-16 Thread Jari Pennanen
User != UserEmail User does not have subject, thus it will raise AttributeError: 'User' object has no attribute 'subject' Secondly, I do not want to create 1+N queries (where N is number of users), with creating a query per user this would be simple but very inefficient. On Jan 16, 12:16 pm, Pra

Re: GROUP BY fields appearance, bug or feature?

2011-01-16 Thread Praveen Krishna R
*First of all did you try accessing the email subject with a dotted notation?* try u = User.objects.all() and u[0].subject On Sun, Jan 16, 2011 at 12:53 PM, Jari Pennanen wrote: > Hi! > > Suppose following model: > > class UserEmail(models.Model): >"""User email""" > >user = models.Forei

Re: GROUP BY and ORDER BY using the ORM

2010-07-05 Thread MikeHowarth
Thanks Euan, some great info there. I'll have a dig through the docs for F objects, I wasn't even aware of them so thanks for point me in that direction! On 5 July, 10:35, "euan.godd...@googlemail.com" wrote: > I'd only use extra as a total last resort as it often results in poor > portability b

Re: GROUP BY and ORDER BY using the ORM

2010-07-05 Thread euan.godd...@googlemail.com
I'd only use extra as a total last resort as it often results in poor portability between DB backends. That said if you're only ever going to stick to one you might not care. Django introduced F objects in 1.1. The documentation is not great and my experiments with it haven't been a massive succes

Re: GROUP BY and ORDER BY using the ORM

2010-07-05 Thread MikeHowarth
You're right I sniped the date_time field when pasting in the model after leaving out some extranous detail. Doh! Ordering by date_time mean't I had duplicates despite grouping by site. Like you say printing out the query may actually help me understand what is going on under the hood. After post

Re: GROUP BY and ORDER BY using the ORM

2010-07-04 Thread euan.godd...@googlemail.com
Erm. You don't seem to have specified what to order by. In this case, surely you want ... .order_by('date_time') However, this field doesn't seem to appear in your models. One thing I've found handy for debugging Django's ORM to SQL is something which I don't think is documented in django docs at

Re: group by

2009-10-01 Thread Karen Tracey
On Thu, Oct 1, 2009 at 4:38 PM, garyrob wrote: > > Hello, > > Suppose I have a model my_model, with several fields, one of which is > x. Suppose it's based on an SQL table with the same name. > > In SQL, I can: > > select x, count(*) > from my_model > group by x > > In order to get the number of

Re: Group By and aggregation

2009-02-13 Thread Russell Keith-Magee
On Fri, Feb 13, 2009 at 6:54 PM, Alessandro wrote: > > > 2009/2/10 Alessandro >> >> >> 2009/2/10 Russell Keith-Magee >>> >>> >>> i.e., plural modules, not singular module, in the Max lookup. It's the >>> reverse lookup name for the module relationship on Module_scheme. For >>> future reference,

Re: Group By and aggregation

2009-02-13 Thread Alessandro
2009/2/10 Alessandro > > > 2009/2/10 Russell Keith-Magee > >> >> >> i.e., plural modules, not singular module, in the Max lookup. It's the >> reverse lookup name for the module relationship on Module_scheme. For >> future reference, the message on the FieldError tells you the right >> name - mod

Re: Group By and aggregation

2009-02-10 Thread Alessandro
2009/2/10 Russell Keith-Magee > > > i.e., plural modules, not singular module, in the Max lookup. It's the > reverse lookup name for the module relationship on Module_scheme. For > future reference, the message on the FieldError tells you the right > name - modules. You're great. It works. Tha

Re: Group By and aggregation

2009-02-10 Thread Russell Keith-Magee
On Tue, Feb 10, 2009 at 8:43 PM, Alessandro wrote: > > > 2009/2/10 Russell Keith-Magee >> >> >> However, if you're using Django trunk, what you want is: >> >> >>> from django.db.models import Max >> >>> qs = >> >>> Module_scheme.objects.filter(plant=3).annotate(max_energy_tot=Max('module__energy

Re: Group By and aggregation

2009-02-10 Thread Alessandro
2009/2/10 Russell Keith-Magee > > > However, if you're using Django trunk, what you want is: > > >>> from django.db.models import Max > >>> qs = > Module_scheme.objects.filter(plant=3).annotate(max_energy_tot=Max('module__energy_tot')) > >>> for mod in qs: > ...print mod.id, mod.max_energy_to

Re: Group By and aggregation

2009-02-10 Thread Russell Keith-Magee
On Tue, Feb 10, 2009 at 6:47 PM, Alessandro Ronchi wrote: > I have to get the max value of a model grouped by a field. > > The RAW SQL query is this: > > SELECT max(energy_tot) FROM fotovoltaico_modules,fotovoltaico_module_scheme > WHERE fotovoltaico_module_scheme.plant_id = 3 AND > fotovoltaico_

Re: GROUP BY

2009-01-27 Thread Glenn Maynard
On Jan 27, 2:50 am, Malcolm Tredinnick wrote: > > I don't care if it takes more than one line, though there is, in > > fact :), a big difference between taking more than one line and having > > to bypass the public API. > > Only semantically, when you're trying to access something like "group > b

Re: GROUP BY

2009-01-26 Thread Malcolm Tredinnick
On Mon, 2009-01-26 at 23:46 -0800, Glenn Maynard wrote: [...] > I don't care if it takes more than one line, though there is, in > fact :), a big difference between taking more than one line and having > to bypass the public API. Only semantically, when you're trying to access something like "gr

Re: GROUP BY

2009-01-26 Thread Glenn Maynard
On Jan 26, 11:42 pm, Malcolm Tredinnick wrote: > That's because it doesn't exist. Django isn't meant to completely > replace the need for SQL, for a start. I was assuming it was possible because the extra() API already seems to try to avoid forcing people to drop out of the ORM entirely for case

Re: GROUP BY

2009-01-26 Thread Russell Keith-Magee
On Tue, Jan 27, 2009 at 1:20 PM, Glenn Maynard wrote: > > On Jan 26, 10:20 pm, Russell Keith-Magee > wrote: >> I'm a little bit confused as to what you think is happening here - >> what do you mean by "other than a simple column"? The default >> aggregate grouping is effectively by object instan

Re: GROUP BY

2009-01-26 Thread Malcolm Tredinnick
On Mon, 2009-01-26 at 20:20 -0800, Glenn Maynard wrote: > On Jan 26, 10:20 pm, Russell Keith-Magee > wrote: > > I'm a little bit confused as to what you think is happening here - > > what do you mean by "other than a simple column"? The default > > aggregate grouping is effectively by object inst

Re: GROUP BY

2009-01-26 Thread Glenn Maynard
On Jan 26, 10:20 pm, Russell Keith-Magee wrote: > I'm a little bit confused as to what you think is happening here - > what do you mean by "other than a simple column"? The default > aggregate grouping is effectively by object instance; the > implementation means that every non-aggregate field on

Re: GROUP BY

2009-01-26 Thread Russell Keith-Magee
On Tue, Jan 27, 2009 at 10:55 AM, Glenn Maynard wrote: > > How are aggregates grouped on anything other than a simple column? I'm a little bit confused as to what you think is happening here - what do you mean by "other than a simple column"? The default aggregate grouping is effectively by obje

Re: Group by week

2008-06-26 Thread Chris H.
On Jun 26, 10:44 am, "Scott Moonen" <[EMAIL PROTECTED]> wrote: > Chris, I have a utility function that does this for me.  You can call it > from your view, or if you set things up right from your template: Good stuff, Scott. Thanks! Might be worth turning into a proper template tag/filter at so

Re: Group by week

2008-06-26 Thread Scott Moonen
Chris, I have a utility function that does this for me. You can call it from your view, or if you set things up right from your template: from datetime import date def most_recent_Sunday(dt = None) : if dt is None : dt = date.today() return date.fromordinal(date.toordinal(dt) - (dt.weekday()

Re: Group by for querysets

2008-05-09 Thread Eric Abrahamsen
> Awesome! Thanks much, Eric! My pleasure... Just noticed there's a typo in the second part, should be columns.setdefault..., not blocks. Hooray for native group_by support in the ORM! I didn't realize that was already in there. --~--~-~--~~~---~--~~ You received

Re: Group by for querysets

2008-05-09 Thread James Bennett
On Fri, May 9, 2008 at 12:47 PM, Chris <[EMAIL PROTECTED]> wrote: > Does django carry something similar to what I am looking for? If not, > would a group_by feature be something worth adding to django? If you're using a recent Django trunk checkout (after the queryset-refactor merge), there is so

Re: Group by for querysets

2008-05-09 Thread gmacgregor
On May 9, 4:57 pm, Eric Abrahamsen <[EMAIL PROTECTED]> wrote: > (Don't forget to reply to the list...) Apologies... didn't realize I hit "Reply to author" > The documentation for the groupby function is notoriously obscure, but > it's actually simple to use. It generates pairs where the first i

Re: Group by for querysets

2008-05-09 Thread Eric Abrahamsen
> This sounds like it might do what I need... Care to share a code > example? > > > Greg (Don't forget to reply to the list...) The documentation for the groupby function is notoriously obscure, but it's actually simple to use. It generates pairs where the first item is the common key for a

Re: Group by for querysets

2008-05-09 Thread Eric Abrahamsen
In the meantime, you can use the groupby template tag for simple grouping operations in the template, or else I've had success using the itertools.groupby function in the view, and then passing your queryset as a dictionary or list of tuples to the template. It will be nice to have native

Re: Group by for querysets

2008-05-09 Thread [EMAIL PROTECTED]
Their is a thread here regarding the GSOC student's work: http://groups.google.com/group/django-developers/browse_thread/thread/f83457fc3cdb235d On May 9, 1:41 pm, gmacgregor <[EMAIL PROTECTED]> wrote: > On May 9, 2:37 pm, gmacgregor <[EMAIL PROTECTED]> wrote: > > > Something like it is being "co

Re: Group by for querysets

2008-05-09 Thread gmacgregor
On May 9, 2:37 pm, gmacgregor <[EMAIL PROTECTED]> wrote: > Something like it is being "considered" but nothing for > sure:http://code.djangoproject.com/ticket/3566 Whoops, I lied: check out the (currently) last comment made by Russ M on the ticket page: "For the benefit of those that haven't h

Re: Group by for querysets

2008-05-09 Thread gmacgregor
On May 9, 1:47 pm, Chris <[EMAIL PROTECTED]> wrote: > Is there a group_by method when getting querysets? Nope... nothing of the sort. You'll have to write raw SQL for that. I'm struggling with the same thing right now. > Check out the following example. > ... > events_by_group = > SportsEvent.o