0

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.

Stuart Grimshaw
  • 1,541
  • 1
  • 18
  • 41

2 Answers2

4

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

Community
  • 1
  • 1
arie
  • 18,737
  • 5
  • 70
  • 76
0

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

Community
  • 1
  • 1
sudobangbang
  • 241
  • 5
  • 15