-
-
Notifications
You must be signed in to change notification settings - Fork 483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom model name prefix #489
Comments
This seems reasonable to me. Thanks for you long description - you clearly put some thought into this. Rather than add yet another parameter to the
The change in models.py would be
What do you think of this as an alternative? |
Whats not to like about that solution - awesome flexibility. Want me to implement and do a PR? |
Go for it! Thanks 👍 |
It appears this was fixed without a |
Problem Statement
The table names become quite long when prepending "Historical" to all base class names to produce the Historical model class name and would like to be able to override the default of using "Historical".
Describe the solution you'd like
Add a class instantiation option "custom_model_name_prefix" to override the default "Historical" implemented so that "custom_model_name" feature takes precedence.
Existing code:
name = ( self.custom_model_name if self.custom_model_name is not None else "Historical%s" % model._meta.object_name )
Proposed code change:
name = ( self.custom_model_name if self.custom_model_name is not None else "Historical%s" % model._meta.object_name if self.custom_model_name_prefix is None else self.custom_model_name_prefix + model._meta.object_name )
Describe alternatives you've considered
I am aware of the ability to completely override the class name using the "custom_model_name" option but that mechanism does not facilitate use in a base class that models inherit from because it cannot dynamically create the class name based on the concrete model class (or perhaps I am not smart enough to figure out how to do it).
Additional context
This feature would allow a shorter model name and would even allow model names to be in the form
where the history models are created in a dedicated app using the "app" option thus making name much more aligned with the base table it is tracking
So for example you might have a model named "Poll" in an app named "mood" and by creating the historical model using:
... you would end up with the table name being tracked as mood_poll and the and the history table as audit_poll
The text was updated successfully, but these errors were encountered: