Constantinius
Constantinius

Reputation: 35069

TabularInlines readonly fields are deleteable

I'm using TabularInlines for administrate many-to-many relationships in the django admin. When some conditions are met, I want to make the inline read only. To achieve this I override the get_readonly_fields() method from the BaseModelAdmin.

This works like a charm, with the only problem, that the read only fields are still deleteable (the checkbox for the deletion is still there and still works).

Of course I could set the can_delete field in the TabularInline to False but this prevents the deletion also for not read only cases.

My question: How can I set up the TabularInline that I can prohibit the deletion in read only fields and enable it if the fields are read/writeable?

EDIT: I use Django 1.3, but if the solution also works for 1.2 it would be perfect!

Upvotes: 1

Views: 180

Answers (1)

Dave
Dave

Reputation: 11899

I think what you want to do is set has_delete_permission(self, obj=None). That will allow you to decide when you can and cannot delete an entire inline.

Upvotes: 1

Related Questions