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/20 11:49] alfred [Django support] |
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 59: | Línea 63: | ||
| comments = ListField(EmbeddedDocumentField(Comment)) | comments = ListField(EmbeddedDocumentField(Comment)) | ||
| </code> | </code> | ||
| - | We also could use ''GenericReferenceField'' to referenci any kind of document: | + | We also could use ''GenericReferenceField'' to reference any kind of document: |
| <code python> | <code python> | ||
| class Bookmark(Document): | class Bookmark(Document): | ||
| 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> | ||