Django

Code

Ticket #1790 (closed: duplicate)

Opened 2 years ago

Last modified 1 year ago

Can't find objects when using subclassed model

Reported by: anonymous Assigned to: adrian
Milestone: Component: Tools
Version: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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>]

Attachments

Change History

05/11/06 14:26:04 changed by Chris Chamberlin <dja <@> cdc.msbx.net>

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.

07/02/06 11:58:43 changed by anonymous

  • severity changed from normal to minor.
  • component changed from Core framework to RSS framework.
  • priority changed from normal to highest.
  • version changed from SVN to new-admin.
  • milestone set to Version 0.91.
  • type changed from defect to task.

07/03/06 02:11:03 changed by anonymous

  • severity changed from minor to blocker.
  • component changed from RSS framework to Tools.
  • priority changed from highest to low.
  • version deleted.
  • milestone changed from Version 0.91 to Version 0.93.
  • type changed from task to enhancement.

08/13/06 00:37:27 changed by Gary Wilson <gary.wilson@gmail.com>

  • milestone changed from Version 0.93 to Version 1.0.

0.93 has come and gone.

01/17/07 16:12:17 changed by

  • milestone deleted.

Milestone Version 1.0 deleted

02/01/07 17:18:02 changed by Michael Radziej <mir@noris.de>

Ehm, is subclassing officially supported at all?

02/01/07 17:23:50 changed by Michael Radziej <mir@noris.de>

  • status changed from new to closed.
  • resolution set to duplicate.

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


Add/Change #1790 (Can't find objects when using subclassed model)




Change Properties
Action