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

Add function that is called before saving a model #175

Open
al3xius opened this issue Aug 23, 2021 · 1 comment
Open

Add function that is called before saving a model #175

al3xius opened this issue Aug 23, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@al3xius
Copy link

al3xius commented Aug 23, 2021

Feature request

Add a function which is called before saving.

Context

I want to implement a updated_at field that contains the Date/Time of the last update. This can easily be implemented with such a function. Other use cases include a field that is dependent on another field eg.: file_extention = "pdf" is dependent on file_path = "/home/Documents/test.pdf"

Solution

Add a "pre_save()" function in the "Model" class that can be implemented by Models. Call this function from the "engine._save()".

Alternative solutions

Calling a function every "save" manually.

Additional context

If added, this has also be added to the documentation.

@al3xius al3xius added the enhancement New feature or request label Aug 23, 2021
al3xius added a commit to al3xius/odmantic that referenced this issue Aug 23, 2021
@art049
Copy link
Owner

art049 commented Sep 25, 2022

Hello thanks for the request.

Have you tried to use pydantic validators to achieve this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants