art049 / art049/odmantic

Add function that is called before saving a model

Open
#175 1 comment 5 reactions 0 assignees View on GitHub
feature
Dominant language
Python
Stars
1.2k
Forks
97
PR merge metrics
No merged PRs in 30d

Description

# 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.

Contributor guide

Open the contributing guide

Research direction

Start by reading the Model class and the engine._save() entry point named in the issue to understand the current save flow. Check the existing documentation and tests around model saving before deciding what coverage is needed. Done means a pre_save() hook is supported for models, is called before saving, and the behavior is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
mongodb, python
Domain
database
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.