Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
278 views
in Technique[技术] by (71.8m points)

Why is setting initial field values not working in django admin?

I have some code that doesn't do what I would expect even after thorough debugging.

I have

class AgregatororderAdmin(admin.ModelAdmin):
   ...

on which I call

def change_view(self, request, object_id, form_url='', extra_context = None):
    if self.form.base_fields["ProcessingPersonAdminId"].initial == None:
        self.form.base_fields["ProcessingPersonAdminId"].initial = request.user.id
        self.form.base_fields["ProcessingPersonName"].initial = request.user.username
    ...
    return super().change_view(request, object_id, form_url, extra_context=extra_context, )

when I check, the initial values, it is set correctly. But in the admin change view it does not display. I would appreciate any hint on why the changes are not applied.

question from:https://stackoverflow.com/questions/65882225/why-is-setting-initial-field-values-not-working-in-django-admin

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...