Opened 11 years ago

Closed 11 years ago

#21156 closed New feature (needsinfo)

Inline model admin does not respect model field default values.

Reported by: tom.vaughan@… Owned by: nobody
Component: contrib.admin Version: 1.5
Severity: Normal 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

Given the abbreviated code below, in the admin view for Project Proposals there will be three (the default value of "extra") new Resubmit Project Proposal Links each with their own unique resubmit_id, and there will be a link to "+ Add another Resubmit Project Proposal Link". This works the first time it's clicked. That is the new (fourth) Resubmit Project Proposal Link will have a unique (distinct from the first three at least) resubmit_id, let's say 1234. But each time the link is clicked afterwards the resubmit_id in the newly created Resubmit Project Proposal Link will always be 1234.

def _default_resubmit_id():
    return uuid.uuid4().hex

class ResubmitProjectProposalLink(models.Model):                                                                                                                   
    resubmit_id = fields.RequiredCharField(default=_default_resubmit_id)
    projectproposal = fields.RequiredForeignKey('ProjectProposal', related_name='resubmit_projectproposal_links')

class ResubmitProjectProposalLinkInline(admin.StackedInline):
    model = ResubmitProjectProposalLink

class ProjectProposalAdmin(admin.ModelAdmin):
    inlines = [ResubmitProjectProposalLinkInline]

Change History (2)

comment:1 by Tim Graham, 11 years ago

Do you have a proposal for how to address this? It seems to be like it would be prohibitively difficult to address in a general fashion as it would require doing something like detecting that the default value should be dynamically generated and then providing an API that could be used to fetch new values when clicking "Add Another". I think you are better off customizing the admin yourself if you need this functionality.

comment:2 by Tim Graham, 11 years ago

Component: Uncategorizedcontrib.admin
Resolution: needsinfo
Status: newclosed
Type: UncategorizedNew feature

Closing as needs info/won't fix in absence of a proposal for how to address this.

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