Opened 16 years ago

Closed 16 years ago

#7713 closed (duplicate)

newforms-admin has issues with model inheritance

Reported by: zobbo Owned by: nobody
Component: contrib.admin Version: newforms-admin
Severity: Keywords: newforms-admin model inheritance
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

You'll need to apply the patch in #7588 to test this, otherwise you'll just get a python traceback

Take the following class:

from django.db import models

# Create your models here.

from django.db import models 
import datetime 

class BaseModel(models.Model): 
    """Abstract class used for some common fields""" 
    created_at = models.DateTimeField(blank=True, default=datetime.datetime.now) 
    modified_at = models.DateTimeField(blank=True, default=datetime.datetime.now) 
    class Meta: 
        abstract = True 

class Item(BaseModel): 
    """Everything in the system - multi table inheritance""" 
    code = models.CharField(blank=True, max_length=15) # A shortname 
    description = models.CharField(blank=True, max_length=50) 

class ValuedItem(Item): 
    """This is an abstract base class for stuff with a value""" 
    value = models.FloatField(default=0.0) 
    class Meta: 
        abstract = True 

class PlayableItem(ValuedItem): 
    """Inheriting from our abstract ValuedItem class""" 
    funfactor = models.IntegerField(blank=True, null=True) # Amount of fun
    
    class Admin:
        pass
        
/* The admin stuff, normally in admin.py */

from django.contrib import admin
from django.contrib.admin.sites import AlreadyRegistered
    
class PlayableItemAdmin(admin.ModelAdmin) :
    model = PlayableItem
    list_display = ('code','description',)
    list_filter = ('code',)
    search_fields=('code','description')    

try:
    admin.site.register(PlayableItem, PlayableItemAdmin)
except AlreadyRegistered:
    pass

Now try and add a playable item through the admin interface. By default the item ptr appears and won't let you save the record until it's been filled in. And of course, you can't fill it in, because the item it needs to point to is not saved yet. I'd assume these ptr fields should be automatically hidden and filled in by the admin mechanism. Attached graphic of the form behaviour.

Attachments (1)

djangobug.png (87.2 KB ) - added by zobbo 16 years ago.
Admin interface behaviour with model inheritance

Download all attachments as: .zip

Change History (2)

by zobbo, 16 years ago

Attachment: djangobug.png added

Admin interface behaviour with model inheritance

comment:1 by Russell Keith-Magee, 16 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #6755.

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