Generic Delete View with Related Objects

I want to create a more generic delete view.
In Django Admin you can see the related objects if you want to delete an item.

How is this achieved?

If you are looking to interrogate a model to see what other models may refer to it, you can use the “get_fields” method on the _meta object to get fields related to you.

If you’re trying to make things more dynamic / use introspection, you’ll probably want to become familar with the Model _meta API.

By identifying which other models refer to your model, you can then get the related instances of that model.

You might get some ideas by looking at the get_deleted_objects method in the source code.

1 Like