Link in Django admin interface to directly download model field from database
===

I'm storing binary files as base64 encoded strings in a model's TextField().  I'm doing it like this:

    class Foo(models.Model):
      _data = models.TextField(db_column='data', blank=True)

      def set_data(self, data):
        self._data = base64.encodestring(data)

      def get_data(self):
        return base64.decodestring(self._data)

      data = property(get_data, set_data)

([from this snippet][1]).

How do I provide a link to download these files (after decoding) from the Django admin interface, preferably from the change/edit page of a model instance?

I can decode them and display them on the page - like any other model field - but it either doesn't show or it's garbage because they're binary files.  I'd like to offer a download link.

Most of the information I can google about Django files assumes I'm taking user uploads or that I want to serve static (media) files from the webserver directly.  Neither is the case.  My files are small, used infrequently, and for administrative use only so it doesn't hurt to store them in the database directly, or have Django serve them itself.


  [1]: http://djangosnippets.org/snippets/1597/