From 905f437c96f411118134920b6da77a4a1279cfa7 Mon Sep 17 00:00:00 2001 From: nesdis <nesdis@gmail.com> Date: Sun, 19 Jul 2020 18:08:53 +0200 Subject: [PATCH] Documentation about improved features on EmbeddedField --- docs/docs/get-started.md | 45 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/docs/docs/get-started.md b/docs/docs/get-started.md index fcb1401..c326b60 100644 --- a/docs/docs/get-started.md +++ b/docs/docs/get-started.md @@ -110,11 +110,54 @@ class Entry(models.Model): By setting `null=False, blank=False` in `EmbeddedField`, missing values are never stored. -<!-- + ## Using MongoDB fields + Nest a `dict` inside a model with the `EmbeddedField`. The `model_container` is used to describe the structure of the + data being stored. + +```python +from djongo import models +class Blog(models.Model): + name = models.CharField(max_length=100) + class Meta: + abstract = True + +class Entry(models.Model): + blog = models.EmbeddedField( + model_container=Blog + ) + headline = models.CharField(max_length=255) + +e = Entry() +e.blog = { + 'name': 'Djongo' +} +e.headline = 'The Django MongoDB connector' +e.save() +``` +Nest a `list` of `dict` inside a model for more complex data. + +```python +from djongo import models + +class Entry(models.Model): + blog = models.ArrayField( + model_container=Blog + ) + headline = models.CharField(max_length=255) + +e = Entry() +e.blog = [ + {'name': 'Djongo'}, {'name': 'Django'}, {'name': 'MongoDB'} +] +e.headline = 'Djongo is the best Django and MongoDB connector' +e.save() +``` + +<!-- ## Simplify complex queries ## Django Admin -- GitLab