views:

238

answers:

1

Hello,

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 :)

+1  A: 

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
Any luck with this?
Greg
Sorry for answering so (very) late. It's now working. I will probably open a new ticket on django website about it. Thank you. ;-)