Hi Michal,
Thanks for the solution. I tried the solution in a different way:
A.objects.annotate(
max_date_created=Max('b__date_created')).filter(b__date_created=F('max_date_created'),
b__text='ABCD')
Hope the above amounts to the same thing as you have suggested.
Thanks.
On Wednesday,
On Tue, Aug 30, 2016 at 11:46:14PM -0700, Web Architect wrote:
> Hi Erik,
>
> I tried your solution but there are some issues:
>
> .filter(date_created=Max('a__b__date_created')) - this is throwing error
> saying not proper use of group function.
>
> If I remove the above, the result isn't cor
Hi Erik,
I tried your solution but there are some issues:
.filter(date_created=Max('a__b__date_created')) - this is throwing error
saying not proper use of group function.
If I remove the above, the result isn't correct where when I go through
each 'a' in the result, associated latest B.text
Thanks Erik. Will try out the solution you mentioned.
On Tuesday, August 30, 2016 at 3:59:20 PM UTC+5:30, Erik Cederstrand wrote:
>
>
> > Den 30. aug. 2016 kl. 11.20 skrev Erik Cederstrand <
> erik+...@cederstrand.dk >:
> >
> > I'm not even sure that's possible to express in SQL, but it would
>
Maybe this can help you
https://docs.djangoproject.com/en/1.10/topics/db/aggregation/
terça-feira, 30 de Agosto de 2016 às 07:33:14 UTC+1, Web Architect escreveu:
>
> Hi,
>
> I am looking for an elegant and efficient mechanism to have a query filter
> or a solution for the following one to many
> Den 30. aug. 2016 kl. 11.20 skrev Erik Cederstrand
> :
>
> I'm not even sure that's possible to express in SQL, but it would probably be
> quite convoluted if it is. Here's an easier-to-understand solution:
>
> res = set()
> for b in B.objects.all().select_related('a').annotate(Max('date_cre
Hi Erik,
Thanks for the solution.
So, I understand we get all instances of B which are max (date created) or
latest (date created) for each instance of A and then we check b.text ==
'ABCD' and select the corresponding instance of A.
Can't we add additional filter to check if text='ABCD' inste
> for b in B.objects.all().select_related('a').annotate(Max('date_created')):
That should probably be: Max('a__b__date_created') instead.
Erik
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving em
I'm not even sure that's possible to express in SQL, but it would probably be
quite convoluted if it is. Here's an easier-to-understand solution:
res = set()
for b in B.objects.all().select_related('a').annotate(Max('date_created')):
if b.date_created != b.date_created__max:
continue
Hi Mike,
Thanks for your response.
I am aware of chaining filters.
The latest() API in django queryset returns an object and not a queryset.
Hence, I cannot add a filter to it.
I had thought about using chaining filters but couldn't find a way.
On Tuesday, August 30, 2016 at 12:18:56 PM UTC
On 30/08/2016 4:33 PM, Web Architect wrote:
Hi,
I am looking for an elegant and efficient mechanism to have a query
filter or a solution for the following one to many relationship model.
Please note the following is just an illustration of the models - hope
it should provide what I am looking
Hi,
I am looking for an elegant and efficient mechanism to have a query filter
or a solution for the following one to many relationship model. Please note
the following is just an illustration of the models - hope it should
provide what I am looking for:
class A(models.Model):
name = models.C
12 matches
Mail list logo