Explicitly setting 'created' date for initial user import from legacy application

20 views
Skip to first unread message

Chris Routh

unread,
Sep 24, 2018, 1:37:11 PM9/24/18
to Django users
Hi all,

I need to explicitly set the created date for users when saving them during an initial import process from a legacy user table. I am using a legacy DB model and trasnforming the models and saving the new user obects. I only need to override the default create behaviour for this one import task, after that I want it to behave normally, so not sure if overriding the model save function in the model definition is appropriate.

I guess I could generate a fixture file and use call_command(loaddata...) to import the users and bypass the default save, but this seems nasty. Is there a better way?

Chris Routh

unread,
Sep 24, 2018, 6:36:21 PM9/24/18
to Django users
Ahh, I've worked out that if I overwrite the created property with `model.created = oldmodel.joined`  and call `.save()` a second time it will work. Cheers folks!
Reply all
Reply to author
Forward
0 new messages