santhosh_dj
santhosh_dj

Reputation: 455

deleting the parent (primary) values when deleting the inline value django admin?

enter image description here

When I am trying to delete the values in inlines using Django admin, the primary key objects are deleting. Please help in solving my problem.

Thanks in advance.

Upvotes: 0

Views: 414

Answers (1)

scharette
scharette

Reputation: 9977

I'm not sure if this is your goal since the question is a bit vague. But if you are using the default Delete button in the bottom left corner, your telling Django to delete the parent model which represent the top level model. To only delete data of the object in the inline section, you must use the check-box in top right corner of the inline and then use one of the save button of the model.

EDIT

If you want to remove the default "Delete" button, I don't think there is any easy way to this. What I'd recommend is to use permission.

You could try this code:

class MyModelAdmin(admin.ModelAdmin):

    def has_delete_permission(self, request, obj=None):
        #Disable delete
        return False

Note that I can't test it, it is just to give an idea of what is available to you.

Upvotes: 2

Related Questions