[Solved]-Django: How can I find which of my models refer to a model

4👍

Django has something called Collector class. It is used by Django when performing a model deletion. What it does seems like exactly what you want. By calling collect() it finds all the references to the object in the model graph. Additionally it offers a way to delete all the found objects, with a delete() call.

That said I’ve never used this class myself, I just know it exists. The API is somewhat convoluted, but if you’re willing to dig into the internals of Django a little bit, it might save you a lot of coding.

👤julx

Leave a comment