Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Binary or BLOB model field

I have a C# program that inserts a pdf inside a MySQL database. Now I want to retrieve that pdf via django but django's models.FileField needs an "Upload To" parameter which means behind the scenes it actually stores the File on the file system rather than in the database. Is there any way I can set up a django model so that I can store the pdf directly inside MySQL?

Regards

like image 738
RaVen Avatar asked Aug 15 '11 11:08

RaVen


People also ask

What is binary field in Django?

BinaryField is a special field to store raw binary data. It can be assigned bytes, bytearray, or memoryview. By default, BinaryField sets editable to False, that is it can't be included in a ModelForm.

What does CharField mean in Django?

CharField is a string field, for small- to large-sized strings. It is like a string field in C/C+++. CharField is generally used for storing small strings like first name, last name, etc. To store larger text TextField is used. The default form widget for this field is TextInput.

What is slug field in Django?

What is SlugField in Django? It is a way of generating a valid URL, generally using data already obtained. For instance, using the title of an article to generate a URL. Let's assume our blog have a post with the title 'The Django book by Geeksforgeeks' with primary key id= 2.

What is On_delete in Django?

The on_delete is one of the parameter which helps to perform database-related task efficiently. This parameter is used when a relationship is established in Django. The on_delete parameter allows us to work with the foreign key.


1 Answers

Just as an update to this, as of Django 1.6, there's now a BinaryField option that will store files up to 4 GB in size. https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.BinaryField

like image 56
Kevin London Avatar answered Oct 21 '22 21:10

Kevin London