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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With