I am using Django 3.2
I have the following model:
class Foo(models.Model):
title = models.CharField()
slug = models.SlugField()
# remaining fields listed below
In Admin manager, I have the model:
class FooAdmin(admin.ModelAdmin):
fieldsets = [
('General', {
'fields': [
'title',
'description',
'information',
'cover_photo',
'gallery',
]
}),
('Details', {
'fields' : [
'is_cancelled',
'start',
'finish',
'video_url',
]
}),
]
prepopulated_fields = {'slug': ('title',), }
admin.site.register(Foo, FooAdmin)
When I attempt to create a new Foo in the admin manager, I get the error:
KeyError: "Key 'slug' not found in 'FooForm'. Choices are: cover_photo, description, finish, gallery, information, is_cancelled, start, title, video_url."
When I add the slug field to the list of fieldsets, it works, but then the slug field is shown on the form (which I don't want).
I know that I can solve this by overriding Foo.save(), but I want the admin manager to handle this for me.
So, how do I use fieldsets with prepopulated fields that are not supposed to appear on the form?