Herramientas de usuario

Herramientas del sitio


fw:mongoengine

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

Ambos lados, revisión anterior Revisión previa
Próxima revisión
Revisión previa
fw:mongoengine [2014/05/20 11:36]
alfred [Dynamic documents]
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 141: Línea 145:
 for post in Post.objects(tags='​mongodb'​):​ for post in Post.objects(tags='​mongodb'​):​
     print post.title     print post.title
 +</​code>​
 +
 +===== Others =====
 +
 +==== Django support ====
 +=== Connecting ===
 +You only need to call ''​connect()''​ somewhere in the settings module.
 +
 +If you were not using another Database backend you may need to add a dummy database:
 +<code python>
 +DATABASES = {
 +    '​default':​ {
 +        '​ENGINE':​ '​django.db.backends.dummy'​
 +    }
 +}
 +</​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>​
fw/mongoengine.1400585811.txt.gz · Última modificación: 2020/05/09 09:24 (editor externo)