Friday, August 29, 2014

related_query_name - what is it?

Django doc says:

New in Django 1.6.
The name to use for the reverse filter name from the target model. Defaults to the value of related_name if it is set, otherwise it defaults to the name of the model:

# Declare the ForeignKey with related_query_name
class Tag(models.Model):
    article = models.ForeignKey(Article, related_name="tags", related_query_name="tag")
    name = models.CharField(max_length=255)

# That's now the name of the reverse filter

However, an object model doesn't have filter() method. I am trying to use related_query_name to filter a model M with a condition on the related objects R. The problem is that result includes instances of M which don't have related objects in R. But I would like to first understand what related_query_name is. Could someone explain? Thanks,


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