Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anterior Revisión previa Próxima revisión | Revisión previa | ||
|
fw:mongoengine [2014/05/26 12:57] alfred [Storing an object inside another] |
fw:mongoengine [2020/05/09 09:25] (actual) |
||
|---|---|---|---|
| Línea 47: | Línea 47: | ||
| * ''date_modified = DateTimeField(default=datetime.datetime.now)'' | * ''date_modified = DateTimeField(default=datetime.datetime.now)'' | ||
| More about this subject in: [[http://docs.mongoengine.org/guide/defining-documents.html#fields]] | More about this subject in: [[http://docs.mongoengine.org/guide/defining-documents.html#fields]] | ||
| + | ==== Storing an object ==== | ||
| + | <code python> | ||
| + | Comment.objects.create(text='Me gusta!') | ||
| + | </code> | ||
| ==== Storing an object inside another ==== | ==== Storing an object inside another ==== | ||
| <code python> | <code python> | ||
| Línea 156: | Línea 160: | ||
| } | } | ||
| } | } | ||
| + | </code> | ||
| + | |||
| + | === Users === | ||
| + | Django authentication classes are included as Document classes so they are compatible. To enable them you should add the following to your settings.py file: | ||
| + | <code python> | ||
| + | AUTHENTICATION_BACKENDS = ( | ||
| + | 'mongoengine.django.auth.MongoEngineBackend', | ||
| + | ) | ||
| + | </code> | ||
| + | Remember to call ''set_password()'' method in ''User'' class when assign a password value: | ||
| + | <code python> | ||
| + | instance.set_password(attrs.get('password', instance.password)) | ||
| </code> | </code> | ||