ioned Alpha is a payment model,
> presumably Gamma is one of the constituent parts -- so why would there
> not be a direct FK relationship between the two? (Or at least a one
> way FK relationship through the intermediate model e.g. Beta->Gamma-
>
> >Alpha.)
>
> On May 5,
> qs = Alpha.objects.filter(gamma__beta__name='Beta').distinct())
> id_list = [x.id for x in qs]
> total =
> Alpha.objects.filter(id__in=id_list).aggregate(total=models.Sum('id')).get('total')
I'm sure this approach would work fine, however I feel like it might
be a performance issue when the
Hrm... didn't quite work...
In [18]: Alpha.objects.filter(gamma__beta__name='Beta').values('name')
Out[18]: [{'name': u'Alpha'}, {'name': u'Alpha'}]
In [19]:
Alpha.objects.filter(gamma__beta__name='Beta').values('name').annotate(subtotal=models.Sum('id'))
Out[19]: [{'subtotal': 2, 'name':
Here's a real simplified version demonstrating what I was (poorly)
trying to explain above:
# models.py
from django.db import models
class Alpha( models.Model ):
name = models.CharField(max_length=10, default='Alpha')
def __unicode__( self ):
return u'%s%s' % (self.name,
I guess I'm writing this to confirm a behaviour and see if there might
be a work around.
It appears that qs.aggregate(Sum('field')) ignores qs.distinct().
If I have something like this:
qs = Model.objects.filter(reverserelation__field=id).distinct()
... then len(qs) will return the correct
[index_start:aggregate_start])
Dunno if this'd be worth an explicit mention in documentation that
changing arguments by overriding __init__ on a model can cause
unexpected behavior. (Or maybe it's already in there, I just haven't
seen it yet.)
On Apr 5, 5:54 pm, Wedg <shak...@gmail.com> wrote
So I've come across a weird bug... just wanted to see if anyone's ever
heard of anything like it...
I've got a set of models which appear to create/save correctly. For
example, if I print mymodel.fkfield_id on the instance before/after
save, it's A-OK.
However, when I try to load the models
7 matches
Mail list logo