MongoEngine / MongoEngine/mongoengine
Automatically check if a document is being created?
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.3k
- Forks
- 1.2k
- Avg merge
- 4h 41m
- Merged PRs (30d)
- 11
Description
The context here is simple, I want to automatically maintain "created" and "last_updated" fields on the model level.
Since the .save() method can be ambiguous (could be either create/update) I couldn't figure out how to do this, specially considering that the python document object might not be in sync with the database document.
Obviously I could implement this at the application's business logic level.
Example :
class Test(Document):
created = DateTimeField()
last_updated = DateTimeField()
def clean(self):
self.last_updated = datetime.now()
if self.being_created:
self.created = datetime.now()
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the model-level clean() and .save() entry points mentioned in the issue, focusing on how creation is distinguished from updates when the Python object may be out of sync with MongoDB. Define how created and last_updated should be maintained automatically, then verify the behavior for both newly created and existing documents.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, python
- Domain
- backend, database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100