Stuart Grimshaw
Stuart Grimshaw

Reputation: 1571

Defining Default Inline value for Django Admin forms?

If I have an inline admin class like this:

class ResourceInline(admin.TabularInline):
    model = Resource
    extra = 3

Is there any way to specify the default values for the 3 "extra" resources because the manual says that the prepopulated_fields doesn't accept ForeignKey fields.

Upvotes: 0

Views: 3739

Answers (2)

sudobangbang
sudobangbang

Reputation: 251

You can also create default values for your inline extra models by targeting the parent admin class that uses ResourceInline as it's inline.

All you have to do is override the add_view function on the parent admin class: Customize Django Admin: Add More Than One Default Inline on Parent Add_View

Upvotes: 0

arie
arie

Reputation: 18972

You could override formfield_for_foreignkey and set the initial value of your fields.

Check this answer to get the basic idea: Default value for user ForeignKey with Django admin

Upvotes: 4

Related Questions