Code

Opened 6 years ago

Closed 5 years ago

#7631 closed (fixed)

Model backward inheritance in newforms admin

Reported by: occulkot@… Owned by: nobody
Component: contrib.admin Version: master
Severity: Keywords:
Cc: mateusz@… Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

class Document(models.Model):
    num = models.CharField(max_length=30)

class DocumentType(Document):
    payment_type = models.IntegerField()
    payment_date = models.DateField()
    client = models.ForeignKey(Client)

class OtherDocument(Document):
    first_field = models.CharField(max_length=111)
    second_field = models.CharField(max_length=123)

class DocumentRow(models.Model)
    document = models.ForeignKey(Document, related_name='rows')
    kind = models.CharField(max_length=30)
    date = models.DateField()

As you can see we have 2 kinds of documents - DocumentType and OtherDocument - every kind of document has same fields as "Document" and aditional fields. And every kind of document should hav rows.
It works perfectly in standard views but its problematic to implement in admin.
i tried

class DocumentRowAdmin(admin.TabularInline):
    extra = 10
    model = models.DocumentRow
    
class DocumentTypeAdmin(admin.ModelAdmin):
    inlines = [DocumentRowAdmin, ]

admin.register(models.DocumentType, PrzesuniecieAdmin)
admin.register(models.OtherDocument, PrzesuniecieAdmin)

And this way it only raises an exception about relationship.
Maybe some "inline_for_parent" option or sth?
im trying to make it working myself but im stuck in BaseModelFormSet.get_queryset method

Attachments (0)

Change History (5)

comment:1 Changed 6 years ago by munhitsu

  • Cc mateusz@… added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 6 years ago by ericholscher

  • milestone set to post-1.0
  • Triage Stage changed from Unreviewed to Design decision needed
  • Version changed from newforms-admin to SVN

comment:3 Changed 6 years ago by Piotr Lewandowski <django@…>

  • Component changed from Uncategorized to Admin interface

comment:4 Changed 5 years ago by anonymous

  • milestone post-1.0 deleted

Milestone post-1.0 deleted

comment:5 Changed 5 years ago by jkocherhans

  • Resolution set to fixed
  • Status changed from new to closed

There are some typos in these models, but I did my best to re-create them, and they work with django trunk as of r10283. Please re-open with more details if this isn't fixed.

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.