From dc7181a3fdef5e5a1724683677fd5bc21298db8f Mon Sep 17 00:00:00 2001 From: Steve Challis Date: Sun, 17 Oct 2010 23:43:58 +0100 Subject: [PATCH] Begun GridFS documentation --- docs/guide/gridfs.rst | 26 ++++++++++++++++++++++++++ docs/guide/index.rst | 1 + mongoengine/django/auth.py | 7 +++---- mongoengine/fields.py | 1 + 4 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 docs/guide/gridfs.rst diff --git a/docs/guide/gridfs.rst b/docs/guide/gridfs.rst new file mode 100644 index 00000000..7c6e8acd --- /dev/null +++ b/docs/guide/gridfs.rst @@ -0,0 +1,26 @@ +====== +GridFS +====== +GridFS support comes in the form of the :class:`~mongoengine.FileField` field +object. This field acts as a file-like object and provides a couple of +different ways of inserting and retrieving data. Metadata such as content-type +can also be stored alongside the stored files. In the following example, an +document is created to store details about animals, including a photo: + + class Animal(Document): + genus = StringField() + family = StringField() + photo = FileField() + + marmot = Animal('Marmota', 'Sciuridae') + + marmot_photo = open('marmot.jpg') # Retrieve a photo from disk + marmot.photo = marmot_photo # Store the photo in the document + + marmot.save() + +So adding file data to a document is as easy as adding data to any other + +.. versionadded:: 0.4 + + diff --git a/docs/guide/index.rst b/docs/guide/index.rst index 7fdfe932..aac72469 100644 --- a/docs/guide/index.rst +++ b/docs/guide/index.rst @@ -10,3 +10,4 @@ User Guide defining-documents document-instances querying + gridfs diff --git a/mongoengine/django/auth.py b/mongoengine/django/auth.py index da0005c8..595852ef 100644 --- a/mongoengine/django/auth.py +++ b/mongoengine/django/auth.py @@ -75,10 +75,9 @@ class User(Document): email address. """ now = datetime.datetime.now() - + # Normalize the address by lowercasing the domain part of the email # address. - # Not sure why we'r allowing null email when its not allowed in django if email is not None: try: email_name, domain_part = email.strip().split('@', 1) @@ -86,12 +85,12 @@ class User(Document): pass else: email = '@'.join([email_name, domain_part.lower()]) - + user = User(username=username, email=email, date_joined=now) user.set_password(password) user.save() return user - + def get_and_delete_messages(self): return [] diff --git a/mongoengine/fields.py b/mongoengine/fields.py index 86da2e3d..23a88dee 100644 --- a/mongoengine/fields.py +++ b/mongoengine/fields.py @@ -20,6 +20,7 @@ __all__ = ['StringField', 'IntField', 'FloatField', 'BooleanField', RECURSIVE_REFERENCE_CONSTANT = 'self' + class StringField(BaseField): """A unicode string field. """