Access embedded documents with CRUD by id.
Project description
[![PyPI version](https://badge.fury.io/py/mongoengine-embedded.svg)](https://badge.fury.io/py/mongoengine-embedded)
# mongoengine-embedded
This package provides basic CRUD methods on EmbeddedDocumentListField through \_id.
## Usage
```python
import mongoengine
from mongoengine_embedded import EmbeddedResource, ResourceContainer
# embedded resource
class Masterpiece(mongoengine.EmbeddedDocument, EmbeddedResource):
title = mongoengine.StringField()
# document contains embedded resource
class Monkey(mongoengine.Document, ResourceContainer):
masterpieces = mongoengine.EmbeddedDocumentListField(
Masterpiece, element_name='masterpiece')
the_monkey = Monkey()
the_monkey.save()
# Create
one_masterpiece = the_monkey.create_masterpiece(title='Complete Works of William Shakespeare')
another_masterpiece = the_monkey.create_masterpiece(title='Siku Quanshu')
another_id = another_masterpiece.id
# Read
another = the_monkey.get_masterpiece_by_id(another_id)
# Update
the_monkey.modify_masterpiece_by_id(another_id, set__name='Jing Shi Zi Ji')
# Destroy
the_monkey.destroy_masterpiece_by_id(another_id)
```
## Installation
This Package can be installed through pip:
```bash
pip install mongoengine-embedded
```
## LICENSE
# mongoengine-embedded
This package provides basic CRUD methods on EmbeddedDocumentListField through \_id.
## Usage
```python
import mongoengine
from mongoengine_embedded import EmbeddedResource, ResourceContainer
# embedded resource
class Masterpiece(mongoengine.EmbeddedDocument, EmbeddedResource):
title = mongoengine.StringField()
# document contains embedded resource
class Monkey(mongoengine.Document, ResourceContainer):
masterpieces = mongoengine.EmbeddedDocumentListField(
Masterpiece, element_name='masterpiece')
the_monkey = Monkey()
the_monkey.save()
# Create
one_masterpiece = the_monkey.create_masterpiece(title='Complete Works of William Shakespeare')
another_masterpiece = the_monkey.create_masterpiece(title='Siku Quanshu')
another_id = another_masterpiece.id
# Read
another = the_monkey.get_masterpiece_by_id(another_id)
# Update
the_monkey.modify_masterpiece_by_id(another_id, set__name='Jing Shi Zi Ji')
# Destroy
the_monkey.destroy_masterpiece_by_id(another_id)
```
## Installation
This Package can be installed through pip:
```bash
pip install mongoengine-embedded
```
## LICENSE
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file mongoengine-embedded-0.2.0.tar.gz
.
File metadata
- Download URL: mongoengine-embedded-0.2.0.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed3c4448871de7354ecea9efcde1390b07b285e6be5e8c2d17cdf03f8eaf79c8 |
|
MD5 | 6f23169f66dd26b331ef679eb1f7346b |
|
BLAKE2b-256 | 077125ac26c7cd103b5a6f4003f05707c0019a72eae1b9c84352d080410f7001 |