[
{
"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
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
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:
>
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
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
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
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
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)
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
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)
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
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
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
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
>
> 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
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.
>
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
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
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
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
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
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
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
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
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
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
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=['
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 ;-
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
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
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
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
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
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
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
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
*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
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
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
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
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
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
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,
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
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
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
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
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_
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
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
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
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
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
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
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
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
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()
> 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
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
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
> 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
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
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
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
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
65 matches
Mail list logo