するためのモデルの外部キーオブジェクトを逆ゲットI参照オブジェクトと、それが継承したオブジェクトでは、次のモデルがあります:私は逆の関係を参照しようとすると、継承されたオブジェクト
class Employee(models.Model):
user = models.OneToOneField(User, blank=True, null=True)
entity = models.ForeignKey('companies.Entity', blank=True, null=True)
brand = models.OneToOneField('companies.Brand', related_name='brand', blank=True, null=True)
class Entity(models.Model):
name = models.CharField('Name', max_length=255, db_index=True)
class Brand(Entity):
company_name = models.CharField(max_length=128, blank=True, null=True)
問題は、私ができる、ですブランドのみエンティティにアクセスしないでください。私はその従業員がブランドに関連付けられるようにしたい。私はこれを試してみました:
brands = Brand.objects.filter(pk=2)
for b in brands:
print b.employee_set.all().query
それは出力:
SELECT * FROM `employee` WHERE `employee`.`entity_id` = 2
私は出力にそれをしたい:
SELECT * FROM `employee` WHERE `employee`.`brand_id` = 2