Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: disallow can_delete on GenericStackedInline

Tags:

I've built this model which contains a generic foreign key:

class MyModel(models.Model):     content_type = models.ForeignKey(ContentType, verbose_name=_('content type'))     object_id = models.PositiveIntegerField(_('object id'))     content_object = generic.GenericForeignKey('content_type', 'object_id') 

Next I've made a generic stacked inline to put it in any ModelAmin class:

class MyModelStackedInline(generic.GenericStackedInline):     model = MyModel     formset = generic.generic_inlineformset_factory(MyModel, can_delete=False)     extra = 0  class SomeOhterModelAdmin(admin.ModelAdmin):     inlines = [MyModelStackedInline] 

However, despite the can_delete=False arg passed by in generic_inlineformset_factory, I always see a Delete checkbox in my admin change_form.

Here is an example: http://img8.imageshack.us/img8/3323/screenshotbe.png

Do you know how to remove this checkbox ?

Thank you :)

like image 435
user176455 Avatar asked Sep 24 '09 10:09

user176455


1 Answers

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 
like image 60
Stan Avatar answered Sep 18 '22 06:09

Stan