On some occasions it might be desirable to programmatically default insert values for certain columns. One example would be code revision tags. If the model needs to digest data before making decisions, Django default insertions might not be enough.
A possible solution for this is to implement a Base model pre_save method which is run before inserting data into tables. This method should be called on the pre_save signal before check_consistency to update default information. For example if the user specifies version control information, this can be inserted in the default tag column
def get_version_tag() -> str:
"Extracts version tag of repository"
...
class MyModel(Base):
def pre_save(self):
self.tag = get_version_tag()
Once this is implemented, we should also include documentation of this functionality in the doc pages (with versioning in mind).
Update related to the JOSS review process raised by @remram44.
On some occasions it might be desirable to programmatically default insert values for certain columns. One example would be code revision tags. If the model needs to digest data before making decisions, Django default insertions might not be enough.
A possible solution for this is to implement a
Base
modelpre_save
method which is run before inserting data into tables. This method should be called on thepre_save
signal beforecheck_consistency
to update default information. For example if the user specifies version control information, this can be inserted in the defaulttag
columnOnce this is implemented, we should also include documentation of this functionality in the doc pages (with versioning in mind).
Update related to the JOSS review process raised by @remram44.
https://github.com/openjournals/joss-reviews/issues/2007