Hi Béres,

many thanks for your quick response.

I am using Django 1.2.1.

I have been wondering whether I am experiencing this problem because
Installation -> CitlData is actually a one-to-many relationship and
values().annotate() cannot deal with that. However, this would be
strange since this is possible when writing raw SQL using 'sum' and
'group by'. Any ideas on this?

The model definitions are the following:

class Installation(models.Model):
    """ETS installations model"""
    citl_id = models.BigIntegerField()
    name = models.CharField(max_length=200)
    citl_permit_id = models.CharField(max_length=50)
    address = models.CharField(max_length=200,null=True)
    address2 = models.CharField(max_length=200,null=True)
    postcode = models.CharField(max_length=20,null=True)
    city = models.CharField(max_length=200,null=True)
    lat =
models.DecimalField(max_digits=10,decimal_places=7,null=True)
    lon =
models.DecimalField(max_digits=10,decimal_places=7,null=True)
    requires_geocode = models.BooleanField(default=False)

    citl_sector = models.ForeignKey(CitlSector)
    nace = models.ForeignKey(Nace, null=True)
    country = models.ForeignKey(Country)
    company = models.ManyToManyField(Company, null=True)

    class Meta:
        verbose_name = 'ETS installation'
        verbose_name_plural = 'ETS installations'

    def __unicode__(self):
        return u'%s' % self.name

class CitlData(models.Model):
    """Model containing information about the emissions/allocations/
offsets of an ETS installation per year"""
    year = models.IntegerField()
    emissions = models.IntegerField(null=True)
    allocations = models.IntegerField(null=True)
    cers = models.IntegerField(null=True)
    erus = models.IntegerField(null=True)
    is_valid = models.BooleanField()

    installation = models.ForeignKey(Installation)

Thanks again for your help!

Kind regards,
Patrick


On 7 Sep, 17:34, Beres Botond <boton...@gmail.com> wrote:
> Hi Patrick,
>
> It *does* support this as far as I know. I've tried/used similar
> queries and it works ok, although ofc not with your models.
> Please post your model definitions for CitlData and Installation, to
> see if there's any issue there.
> Also what version of Django are you using?
>
> Best Regards,
>
> Béres Botond
>
> On Sep 7, 2:12 pm, patrick <cras...@gmail.com> wrote:
>
>
>
>
>
> > Does the values().annotate() functionality not support grouping by
> > joined table fields or am I missing something here?
>
> > Any help much appreciated!
>
> > Thanks,
> > Patrick

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.

Reply via email to