Code

Opened 6 years ago

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

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 6 years ago.
Admin interface behaviour with model inheritance

Download all attachments as: .zip

Change History (2)

Changed 6 years ago by zobbo

Admin interface behaviour with model inheritance

comment:1 Changed 6 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #6755.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.