Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Third-party-app for merging Django user objects?

I need to merge two users in a Django database. So I wonder if there is any simple way (maybe a dedicated app) to do that?

For example:

We have user_a and user_b and some models that have foreign keys to the User model (Books, Interests, Teams and so on…).

By merging users, I want to delete the object user_b and to set all foreign keys pointing to this object to point to user_a. And – this is my main concern – I want the objects that need to be changed because they reference the to-be-deleted object to be determined automatically without having to specify a list of those Models and foreign key fields in them manually.

Is this already implemented and I'm reinventing the wheel?

Is this possible?

If not, please show me the way to do it: how can I build a list of Django models that have a foreign key to a specific model (User in my case) in runtime?

Thank you for your time.

like image 903
kotslon Avatar asked Sep 01 '25 04:09

kotslon


1 Answers

I found this snippet http://djangosnippets.org/snippets/2283/ . I'm going to have to modify it though, to make it recursive. I will share my code once I'm done.

like image 192
antonagestam Avatar answered Sep 03 '25 08:09

antonagestam