title: Django with Pluggable MongoDB Storage troubles
body: <p>I'm trying to use django, and mongoengine to provide the storage backend only with GridFS. I still have a MySQL database.</p>
  
  <p>I'm running into a strange (to me) error when I'm deleting from the django admin and am wondering if I am doing something incorrectly.</p>
  
  <p>my code looks like this:  </p>
  
  <pre><code># settings.py
  from mongoengine import connect
  connect("mongo_storage")
  
  # models.py
  from mongoengine.django.storage import GridFSStorage
  class MyFile(models.Model):
      name = models.CharField(max_length=50)
      content = models.FileField(upload_to="appsfiles", storage=GridFSStorage())
      creation_time = models.DateTimeField(auto_now_add=True)
      last_update_time = models.DateTimeField(auto_now=True)
  </code></pre>
  
  <p>I am able to upload files just fine, but when I delete them, something seems to break and the mongo database seems to get in an unworkable state until I manually delete all FileDocument.objects. When this happens I can't upload files or delete them from the django interface.</p>
  
  <p>From the stack trace I have: </p>
  
  <pre><code>/home/projects/vector/src/mongoengine/django/storage.py in _get_doc_with_name
          doc = [d for d in docs if getattr(d, self.field).name == name] ...
  ▼ Local vars
  Variable    Value
  _[1]    
  []
  d   
  
  docs    
  Error in formatting: cannot set options after executing query
  name    
  u'testfile.pdf'
  self    
  
  /home/projects/vector/src/mongoengine/fields.py in __getattr__
          raise AttributeError 
  </code></pre>
  
  <p>Am I using this feature incorrectly?</p>
  
  <h1><strong>UPDATE:</strong></h1>
  
  <p>thanks to @zeekay's answer I was able to get a working gridfs storage plugin to work. I ended up not using mongoengine at all. I put my adapted solution on <a href="https://github.com/madisona/django-mongo-storage" rel="noreferrer">github</a>. There is a clear sample project showing how to use it. I also uploaded the project to <a href="http://pypi.python.org/pypi/django-mongo-storage/" rel="noreferrer">pypi</a>.</p>
  
  <h1><strong>Another Update:</strong></h1>
  
  <p>I'd highly recommend the <a href="http://code.welldev.org/django-storages" rel="noreferrer">django-storages</a> project. It has lots of storage backed options and is used by many more people than my original proposed solution.</p>