Allow Users to override tracker class#4
Conversation
browniebroke
left a comment
There was a problem hiding this comment.
I'm not a maintainer, but as a user of this lib, I can see how this might be useful 👍🏻
I left an idea/suggestion, although it doesn't have to be implemented.
| def __init__(self, *args, **kwargs): | ||
| super().__init__(*args, **kwargs) |
There was a problem hiding this comment.
Is this doing anything? Seems like it can be removed...
| class TrackingModelMixin(object): | ||
|
|
||
| TRACKED_FIELDS = None | ||
| tracker_class = Tracker |
There was a problem hiding this comment.
I imagine it might convenient to be able to configure the same Tracker class project-wide, rather than setting this attribute on each models that subclass TrackingModelMixin.
With that in mind, I would suggest a Django setting TRACKING_MODEL_TRACKER_CLASS (or something along these lines) to set an import path for a class to use everywhere, whihc value would default to "tracking_model.Tracker".
However, it does make the implementation a bit more complicated. A keyword here is "imagine": it's not a problem I faced, just something I think I might need.
There was a problem hiding this comment.
able to configure the same Tracker class project-wide
For project-wide usage, I thought that one could easily subclass TrackingModelMixin and override the tracking_class and use it everywhere. (Took DRF's approach here)
But yeah, from the end user perspective, this settings approach would completely eliminate the overriding.
There was a problem hiding this comment.
That's actually a great solution, much simpler and direct than a setting.
|
Hey, thanks for PR, I will look into it shortly, seems like I don't get notifications here so sorry for late response (gotta make sure it does not happen again too). |
44d7f41 to
71181e6
Compare
|
Hi @sumit4613, |
|
Hey @drozdowsky, your changes look good to me. Please go ahead, no objections. |
Motivation
Currently
Trackeris tightly coupled withTrackingModelMixin, if we want to add some methods that replicate the behavior ofmodel_utils.FieldTrackermethods, we need to override theTrackingModelMixinand rewrite thetrackerproperty and write a new Tracker class with the required methods.To avoid this, I'm adding a new attribute
tracker_classtoTrackingModelMixinwhich defaults toTracker.This helps us to easily override the
Trackerand write required methods, without duplicated lines of code.@drozdowsky @browniebroke please let me know what you think about this approach.
Finally, thank you ❤️ for creating this library, it helped me solve some problems that were coming up because of
FieldTracker.