Opened 19 years ago
Closed 18 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 , 19 years ago
comment:2 by , 18 years ago
Component: | Core framework → RSS framework |
---|---|
milestone: | → Version 0.91 |
priority: | normal → highest |
Severity: | normal → minor |
Type: | defect → task |
Version: | SVN → new-admin |
comment:3 by , 18 years ago
Component: | RSS framework → Tools |
---|---|
milestone: | Version 0.91 → Version 0.93 |
priority: | highest → low |
Severity: | minor → blocker |
Type: | task → enhancement |
Version: | new-admin |
comment:7 by , 18 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
closing as duplicate of #1656: model inheritance is not fully implemented.
Note:
See TracTickets
for help on using tickets.
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.