I'm currently maintaining a legacy system while a new system is brought up. I noticed recently that I get a timeout when trying to delete certain objects from a specific model. I've tracked this down to being related to the following question which has an accepted answer: Django admin hangs (until timeout error) for a specific model when trying to edit/create
The problem I'm having is that the objects that are related are not directly related from my model in question.
For example I have the following models (generically named to remain vague due to IP at my company):
ModelAwhich is the model I'm seeing the issue with when deleting from the Django Admin siteModelBwhich contains a ForeignKey field toModelAModelCwhich contains a ForeignKey field toModelBModelDwhich contains a ForeignKey field toModelCModelEwhich contains a ForeignKey field toModelD
Model details:
ModelEcan contain tens/hundreds/thousands of entries for any entry ofModelC. AdditionallyModelCcan contain tens/hundreds/thousands of entries for any entry ofModelB
Currently when I try to delete ModelA Django attempts to generate all the associated objects all the way down to ModelE which is causing a timeout in certain cases with high number of associated ModelC and ModelE.
Is there a way to avoid this either by overriding a custom template such as delete_confirmation_template or through any other method? Ideally I would like to still show the summary, but I'm not sure that will be possible with the nature of this issue.
A few details for context:
- I feel this may be due to a poor overall structure in our DB Schema, but like I mentioned earlier this is a Legacy system.
- I do not need an immediate fix for this as I will actually never delete entries for this model except for my current scenario/task of cleaning up duplicated entries(user error not controlled correctly by forms; The forms now check for this) which is being done through a migration script. I simply noticed this when trying to clean up things and leverage this intermediate page as a sanity check when testing said migration script