id summary reporter owner description type status component version severity resolution keywords cc stage has_patch needs_docs needs_tests needs_better_patch easy ui_ux 22207 Add `related_query_name` to GenericRelation for query operations (filter, order_by, etc.) from related model Gabe Jackson nobody "`related_name` (reverse relation) should be added to GenericRelation to allow filtering from the related model. The following patch provides this functionality including tests and documentation: [https://github.com/gabejackson/django/compare/generic_rel_reverse?expand=1] This is particularly useful for the following use cases: {{{ class Product(model.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = GenericForeignKey('content_type', 'object_id') class CarProduct(model.Model): product = generic.GenericRelation('Product', related_name='cars') # complex hierarchy of models accurately representing a car # ... class WineProduct(model.Model): product = generic.GenericRelation('Product', related_name='wines') # complex hierarchy of models accurately representing wine # ... # Get all Cars as Products based on some specific criteria of the car, and order them by another property >>> Product.objects.filter(cars__wheels__num_spokes=4).order_by(cars__windows__transparency) }}} This should also fix #16920 This is also very useful for django-filter ([https://github.com/alex/django-filter]) allowing to filter over GFKs when GenericRelations are defined." New feature closed contrib.contenttypes dev Normal fixed contenttypes, generic, genericrelation, reverse Unreviewed 1 0 0 0 0 0