Opened 9 years ago
Last modified 9 years ago
#25354 closed New feature
Can't use related_query_name on an abstract base class — at Initial Version
Reported by: | James Pulec | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.8 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
It currently isn't possible to set related_query_name on a field on an abstract base class using the "%(class)s" or "%(app_label)s" string formatting syntax that is allowed for the related_name parameter of field. This is particularly problematic when trying to define an abstract base class that uses a GenericRelation, since you can't specify a related_name, but can specify a related_query_name.
For Example:
Code highlighting:
class Child(models.Model): object_id = PositiveIntegerField() content_type = ForeignKey(ContentType) content_object = GenericForeignKey() class GenericMixin(models.Model): relation = GenrericRelation(Child, related_query_name='%(class)s') class Meta: abstract = True class Parent(GenericMixin): name = CharField() instance = Child.objects.filter(parents__name) # This query will not work, as 'parents' is not set as the related_query_name for the Parent Model
Note:
See TracTickets
for help on using tickets.