disable delete checkbox in Inline formset

4,573 views
Skip to first unread message

Kurczak

unread,
Sep 8, 2008, 2:30:37 PM9/8/08
to Django users
Hi there,
Is there any way to disable/remove the delete checkbox for inline
formsets ( in admin) ?
I found nothing about it in docs, and I believe there's no way to pass
the 'can_delete' parameter to inlineformset_factory. Obviously I can
disable the "Can delete" permission, but the ugly box is still there.

Can anyone help me out with that matter?
Cheers!


David Zhou

unread,
Sep 8, 2008, 2:37:42 PM9/8/08
to django...@googlegroups.com
On Sep 8, 2008, at 2:30 PM, Kurczak wrote:

> Is there any way to disable/remove the delete checkbox for inline
> formsets ( in admin) ?
> I found nothing about it in docs, and I believe there's no way to pass
> the 'can_delete' parameter to inlineformset_factory. Obviously I can
> disable the "Can delete" permission, but the ugly box is still there.

Have you tried editing the admin templates to not show the checkbox?

---
David Zhou
da...@nodnod.net

Kurczak

unread,
Sep 8, 2008, 2:55:15 PM9/8/08
to Django users
Hi David,
thanks for your reply.
I just did in fact, but that affects every single inline form in the
project, and that's not what I want. There's no way to load inline
template (in admin) for selected app from what I learned. And I'd
rather not modify anything in django code because i don't really
consider that as solution.
Is there any other way?



> ---
> David Zhou
> da...@nodnod.net

Daniel Roseman

unread,
Sep 8, 2008, 4:03:26 PM9/8/08
to Django users
Well, it's not true that you can't change the inline template for a
model - you can easily do so by using the 'template' attribute in the
InlineModelAdmin class, see here:
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodeladmin-objects

However a better solution would probably be to define your own custom
formset for the inline model, and set can_delete to false there. For
example:

from django.forms import models
from django.contrib import admin

class MyInline(models.BaseInlineFormset):
def __init__(self, *args, **kwargs):
super(MyInline, self).__init__(*args, **kwargs)
self.can_delete = False

class InlineOptions(admin.StackedInline):
model = InlineModel
formset = MyInline

class MainOptions(admin.ModelAdmin):
model = MainModel
inlines = [InlineOptions]


--
DR

David Zhou

unread,
Sep 8, 2008, 4:02:46 PM9/8/08
to django...@googlegroups.com


You're not really modifying django, since you can include the templats
in your templates folder, and override them.

If you want app specific admin templates, one way is to wrap the admin
views -- for example, see:

http://trac.django-cms.org/trac/browser/trunk/cms/admin_views.py

---
David Zhou
da...@nodnod.net

Kurczak

unread,
Sep 8, 2008, 5:08:03 PM9/8/08
to Django users
Thank you, I'll look into that.
Reply all
Reply to author
Forward
0 new messages