Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think you are better off not using MongoEngine for this, I haven't had much luck with it either. Here is a drop-in replacement for <code>mongoengine.django.storage.GridFSStorage</code>, which works with the admin.</p> <pre><code>from django.core.files.storage import Storage from django.conf import settings from pymongo import Connection from gridfs import GridFS class GridFSStorage(Storage): def __init__(self, host='localhost', port=27017, collection='fs'): for s in ('host', 'port', 'collection'): name = 'GRIDFS_' + s.upper() if hasattr(settings, name): setattr(self, s, getattr(settings, name)) for s, v in zip(('host', 'port', 'collection'), (host, port, collection)): if v: setattr(self, s, v) self.db = Connection(host=self.host, port=self.port)[self.collection] self.fs = GridFS(self.db) def _save(self, name, content): self.fs.put(content, filename=name) return name def _open(self, name, *args, **kwars): return self.fs.get_last_version(filename=name) def delete(self, name): oid = fs.get_last_version(filename=name)._id self.fs.delete(oid) def exists(self, name): return self.fs.exists({'filename': name}) def size(self, name): return self.fs.get_last_version(filename=name).length </code></pre> <p><code>GRIDFS_HOST</code>, <code>GRIDFS_PORT</code> and <code>GRIDFS_COLLECTION</code> can be defined in your settings or passed as <code>host</code>, <code>port</code>, <code>collection</code> keyword arguments to <code>GridFSStorage</code> in your model's <code>FileField</code>.</p> <p>I referred to Django's <a href="https://docs.djangoproject.com/en/dev/howto/custom-file-storage/" rel="nofollow noreferrer">custom storage</a> documenation, and loosely followed <a href="https://stackoverflow.com/questions/1448386/django-custom-storage-system-for-gridfs-mongodb/5202247#5202247">this answer</a> to a similar question. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload