Opened 10 years ago

Closed 10 years ago

#1790 closed enhancement (duplicate)

Can't find objects when using subclassed model

Reported by: anonymous Owned by: Adrian Holovaty
Component: Tools Version:
Severity: blocker Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


Using the latest version from SVN, there seems to be a problem with fetching objects created with a subclassed model.

# Model Definitions

from django.db import models

class Animal(models.Model):
    owner = models.CharField(maxlength=30)

class Cat(Animal):
    name = models.CharField(maxlength=30)
    breed = models.CharField(maxlength=30)

    def __repr__(self):

Testing the model:

>>> from project.test.models import Cat
>>> my_cat = Cat(id=1, owner='Johnny', breed='Persian', name='Kitty')
>>> Cat.objects.all()
>>> from django.db import connection
>>> cursor = connection.cursor()
>>> cursor.execute("""SELECT * FROM test_cat""")
>>> for row in cursor.fetchall(): print row
(1, 'Johnny', 'Kitty', 'Persian') 
>>> # creating (and fetching) Animal objects works just fine
>>> animal = Animal(id=1, owner='Sarah')
>>> Animal.objects.all()
[<Animal object>]
>>> Cat.objects.all()
[<Animal object>]

Change History (7)

comment:1 Changed 10 years ago by Chris Chamberlin <dja <@…>

The bug appears to be that the sub-model doesn't get its own Manager object, but instead inherits the parent's Manager.

The workaround is to explicitly define the "objects" manager in the sub-model's definition, as described in the API documentation on renaming the default manager.

comment:2 Changed 10 years ago by anonymous

Component: Core frameworkRSS framework
milestone: Version 0.91
priority: normalhighest
Severity: normalminor
Type: defecttask
Version: SVNnew-admin

comment:3 Changed 10 years ago by anonymous

Component: RSS frameworkTools
milestone: Version 0.91Version 0.93
priority: highestlow
Severity: minorblocker
Type: taskenhancement
Version: new-admin

comment:4 Changed 10 years ago by Gary Wilson <gary.wilson@…>

milestone: Version 0.93Version 1.0

0.93 has come and gone.

comment:5 Changed 10 years ago by (none)

milestone: Version 1.0

Milestone Version 1.0 deleted

comment:6 Changed 10 years ago by Michael Radziej <mir@…>

Ehm, is subclassing officially supported at all?

comment:7 Changed 10 years ago by Michael Radziej <mir@…>

Resolution: duplicate
Status: newclosed

closing as duplicate of #1656: model inheritance is not fully implemented.

Note: See TracTickets for help on using tickets.
Back to Top