Opened 11 years ago

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


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

Change History (5)

comment:1 Changed 11 years ago by munhitsu

Cc: mateusz@… added

comment:2 Changed 11 years ago by Eric Holscher

milestone: post-1.0
Triage Stage: UnreviewedDesign decision needed
Version: newforms-adminSVN

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

Component: UncategorizedAdmin interface

comment:4 Changed 10 years ago by (none)

milestone: post-1.0

Milestone post-1.0 deleted

comment:5 Changed 10 years ago by jkocherhans

Resolution: fixed
Status: newclosed

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.

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