Opened 10 years ago

Closed 9 years ago

#1790 closed enhancement (duplicate)

Can't find objects when using subclassed model

Reported by: anonymous Owned by: adrian
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 changed from Core framework to RSS framework
  • milestone set to Version 0.91
  • priority changed from normal to highest
  • Severity changed from normal to minor
  • Type changed from defect to task
  • Version changed from SVN to new-admin

comment:3 Changed 10 years ago by anonymous

  • Component changed from RSS framework to Tools
  • milestone changed from Version 0.91 to Version 0.93
  • priority changed from highest to low
  • Severity changed from minor to blocker
  • Type changed from task to enhancement
  • Version new-admin deleted

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

  • milestone changed from Version 0.93 to Version 1.0

0.93 has come and gone.

comment:5 Changed 10 years ago by anonymous

  • milestone Version 1.0 deleted

Milestone Version 1.0 deleted

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

Ehm, is subclassing officially supported at all?

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

  • Resolution set to duplicate
  • Status changed from new to closed

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

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