Hey,
Looking to add a functionality where we can keep with a model instance the user that created it (e.g. fk reference)
What I have considered:
- Something with post_save signals, but getting the post_save to have access to the request seems tricky (and perhaps not even a good idea, kind of breaking the abstraction there).
- add a field to the forms (as a hidden field or something). Then the view adds request.user to the context (probably with a mixin), I add it to the form behind the scene & save it with the instance.
- Create a mixin for my CreateViews/UpdateViews. When I save the object, I add it there & save it again (or just set the attribute & then save).
Any simpler/cleaner way I’m not seeing? I feel I’m going to add it as a form fields, however it’s a bit of a pain to add that to all create/update templates where I want to use it.
EDIT: I guess one option would be to do the opposite? Could I plug a post_save() signal to my subclass of AbstractUser, each time an object is saved and keep sort of a log of saves for each user there? I guess though as times goes on, it’s going to get slower & slower to retrieve which user created a specific object, so that doesn’t scale up very well for my use case. E.g. I will have to display “Created by” in some screens for some object Foo… so after 100 000s of objects gets created, this may not work so welll…