14👍
✅
Update 2016: as per Stan’s answer below, modern versions of django let you set can_delete = True
on the GenericStackedInline
subclass, as it inherits from InlineModelAdmin
I’ve run into this before – for some reason passing can_delete as an argument doesn’t work, but setting it in the formset’s init method does. Try this:
class MyInlineFormset(generic.generic_inlineformset_factory(MyModel)):
def __init__(self, *args, **kwargs):
super(MyInlineFormset, self).__init__(*args, **kwargs)
self.can_delete = False
then in your admin inline class:
class MyModelStackedInline(generic.GenericStackedInline):
model = MyModel
formset = MyInlineFormset
extra = 0
👤Greg
45👍
Maybe It is a post ’09 feature, but you can specify that without overriding the __init__()
method :
class StupidCarOptionsInline(admin.StackedInline):
model = models.StupidOption
form = StupidCarOptionAdminForm
extra = 0
can_delete = False
👤Stan
- [Django]-Base template for all apps in Django
- [Django]-Factory Boy random choice for a field with field option "choices"
- [Django]-Django and App Engine
Source:stackexchange.com