Saturday, March 29, 2014

Annotate concat() of two fields

Hi, I want to annotate the concatenation of two string fields, something like


however it is not possible to use F expressions on annotate().

I'm trying to accomplish the same thing using extra() however I don't
know how to do it right, :(

I have the following Domain model:

class Domain(models.Model):
name = models.CharField(max_length=256, unique=True)
top = models.ForeignKey('domains.Domain', null=True)

which top being a self referencing field,

I want an annotation with the concatenation of " +"

What I have so far is something like

'structured_name': 'CONCAT(,'

Notice that I'm using T2 which is the JOIN table, But this doesn't
always work, because it depends on the total number of joins performed
by the queryset, (so the name changes to T4, etc)

What would be the right way of doing this concat() annotation?


You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment