7 | 7 | This is easily solved if you're OK with sprinkling details of the GenericForeignKey implementation in Django core: you can just try `attname`, and if that fails, filter on GFK's `ct_field` and `pk_field`. But maybe a better idea would be to introduce a method on field-like things returning a dictionary of filter parameters matching a given object, or else a property returning a sequence of (filter name, attribute name) pairs from which the filter parameters can be constructed. In the latter case, regular fields would return `((self.name, self.attname),)`, and GFKs would return `((self.fk_field, self.fk_field), (self.ct_field, self.ct_field))`. |