Opened 18 years ago

Closed 17 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: no UI/UX: no

Description

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):
        return self.name

Testing the model:

(InteractiveConsole)
>>> from project.test.models import Cat
>>> my_cat = Cat(id=1, owner='Johnny', breed='Persian', name='Kitty')
>>> my_cat.save()
>>>
>>> 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.save()
>>> Animal.objects.all()
[<Animal object>]
>>> Cat.objects.all()
[<Animal object>]

Change History (7)

comment:1 by Chris Chamberlin <dja <@…>, 18 years ago

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 by anonymous, 18 years ago

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

comment:3 by anonymous, 18 years ago

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

comment:4 by Gary Wilson <gary.wilson@…>, 18 years ago

milestone: Version 0.93Version 1.0

0.93 has come and gone.

comment:5 by (none), 17 years ago

milestone: Version 1.0

Milestone Version 1.0 deleted

comment:6 by Michael Radziej <mir@…>, 17 years ago

Ehm, is subclassing officially supported at all?

comment:7 by Michael Radziej <mir@…>, 17 years ago

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