Skip to content
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

Pre save hook #45

Closed
ckoerber opened this issue Jan 30, 2020 · 2 comments
Closed

Pre save hook #45

ckoerber opened this issue Jan 30, 2020 · 2 comments

Comments

@ckoerber
Copy link
Member

ckoerber commented Jan 30, 2020

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.

openjournals/joss-reviews#2007

@ckoerber ckoerber moved this from To do to In progress in v1.1.0 [JOSS Review Updates] Feb 4, 2020
ckoerber pushed a commit that referenced this issue Feb 5, 2020
@ckoerber ckoerber moved this from In progress to Done in v1.1.0 [JOSS Review Updates] Feb 5, 2020
@ckoerber
Copy link
Member Author

This feature, docs and test have been implemented in the commit range https://github.com/callat-qcd/espressodb/compare/19ac1c8..ceef601

@ckoerber
Copy link
Member Author

Closed with #48

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

No branches or pull requests

1 participant