Empty QuerySet for Django Multi-Table Inheritance Subclass

97 Views Asked by At

I have the following models:

APP 1:

class User(AbstractBaseUser):
    # custom fields etc
    # NOT ABSTRACT


APP 2:

class SecondaryUser(User):
    # other custom fields

When I do SecondaryUser.objects.create(...) I get an instance as expected:

In: SecondaryUser.objects.create(first_name='test', last_name='test', email='[email protected]')
Out: <SecondaryUser>

This has an id and populated fields as expected. I can also query the base class and use the django-generated 1-1 field for the inheritance to access the subclass's fields:

User.objects.get(email='[email protected]').secondaryuser.<some_field>

However when I do SecondaryUser.objects.all() it returns an empty queryset. And the model admin for the SecondaryUser shows an empty list view (even when I create a new instance of SecondaryUser in the admin create view).

I feel like I'm missing something obvious, I need to be able to list the SecondaryUser instances in the admin. The User class cannot be abstract.

EDIT: have confirmed they're in the DB:

mysql> SELECT * from <app2>_secondaryuser;
+-------------+---------------+-----------+
| user_ptr_id | <field_1>     | <field_2> |
+-------------+---------------+-----------+
|        123  |             0 |         0 |
|        124  |             0 |         0 |
|        125  |             1 |         0 |
+-------------+---------------+-----------+
0

There are 0 best solutions below