SQL Server filter with django-mssql

I would like to use the SQL Server filter function to store files (mostly large images) from a Django application. I am currently using django-mssql as the database for my Django project. I don't think there is an existing model field in this package associated with the Filestream column in SQL Server.

What would be the best way to use the filestream function from Django? Are there existing packages? Or do I need to implement my own custom model field inherited from Django's built-in fields (FileField or BinaryField)?

Thank!

+3


source to share


1 answer


Just in case anyone else is interested in using the SQL Server filtering feature and ends here, I started working with django custom fields to support Filestream: a FileStreamDataField

, which maps to a type varbinary(max) FILESTREAM

and FileStreamField

which is a virtual field that wraps the win32 streaming API.

import uuid

from django.db import models
from sql_filestream import FileStreamDataField, FileStreamField, UUIDField

class DocumentModel(models.Model):
    doc_id = UUIDField(default=uuid.uuid4)
    doc_content = FileStreamDataField(identifier_field='doc_id', null=True, blank=True)
    document = FileStreamField('doc_id', 'doc_content') 

      



You can find examples here: https://github.com/rparent/django-mssql-filestream It works well in my case, but is certainly incomplete. Contributions are welcome!

+1


source







All Articles