I have a table, Credit, that I want to query based on a value several hops away. There's a CreditLineItems that has a Generic Foreign Key to one of two tables, each of which has a Foreign Key to the table I want to search. I've not as yet setup a reverse relation in the related tables.
My question is, given the structure below, how do I return a selection of Credits based on a value in Registration?
class Credit(models.Model):
""" Model queried """
class CreditLineItem(models.Model):
credit = models.ForeignKey(Credit)
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type', 'object_id') #assumed values...
# The GenericForeignKey could point to
class Enrollment(models.Model):
registration = models.ForeignKey(Registration, blank=True)
--OR--
class ProductSale(models.Model):
registration = models.ForeignKey(Registration, blank=True)
class Registration(models.Model):
registration_number = models.IntegerField(db_index=True)