Timothy
Timothy

Reputation: 379

Django querying an inherited model

I have something similar to the example below

from django.db import models    
from django.contrib.auth.models import User

class a(models.Model):
   user = models.ForeignKey(User)

class b(a):
   value = models.IntegerField()

class c(a):
   model_id = models.IntegerField()

I have a User instance assigned to variable current_user, is there any way I can make current_user.b_set work? Thank you for reading.

Upvotes: 1

Views: 91

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798626

The FK is on a, not b, so there is no "b_set". You can query User for objects that have an a that have a b, but a_set is the only property you have.

Upvotes: 1

Related Questions