Questions tagged [filefield]
299 questions
2
votes
0 answers
django storages - save absolute path in database?
How can I save absolute paths (like /var/files/.. , or s3://bucket/path) in a table containing file field?
Django by default uses MEDIA_ROOT as a prefix, and store relative paths.
I use the django-storages package for S3 backend.

user3599803
- 6,435
- 17
- 69
- 130
2
votes
3 answers
File is always empty after submiting FileField
I have a form where I need to gather some text data and a file.After submiting, the textFields are fine, but the FileField seems to be empty.
The validator FileRequired claims that the field is empty, and if I remove it it is indeed NoneType.
Form…

Adrián Varona
- 21
- 1
2
votes
1 answer
Read data of Django FileField
I am trying to save/download the data on local directory before save it to database, which is selected in Django FileField. After download how do I maintain the instance of that selected file in that FileField so that I can save it to database?

Shashi
- 2,137
- 3
- 22
- 37
2
votes
0 answers
Django: get_or_create() and FileField
I like the get_or_create() and update_or_create() methods a lot.
They don't seem to work with FileField.
If I try this:
blob, created = Blob.objects.get_or_create(name='foo2',
defaults=dict(content_file='my_content'))
... I…

guettli
- 25,042
- 81
- 346
- 663
2
votes
1 answer
Improve file_field_tag appearance
Further to the answer provided to this question regarding the appearance improvement of the file_field_tag, how can I replace the "Choose file" text with the filename after selection?

kouroubel
- 260
- 4
- 18
2
votes
1 answer
Edit uploaded file (djangos FileField) using pre_save signal
I want to edit an uploaded file on byte level (i.e. searching and removing a certain byte sequence) before saving it.
I have a pre_save signal set up in the following way:
class Snippet(models.Model):
name = models.CharField(max_length=256,…

David Schumann
- 13,380
- 9
- 75
- 96
2
votes
1 answer
Django: Uploading a file to a REST API with a FileField in a model
So here is the context. I am using Django with Python3.6, and we're using Django REST Framework to build our REST API. I have a simple form on a page, but it is not submitted directly. I am calling manually our API using axios.
Here's the code used…

VisionElf
- 41
- 6
2
votes
1 answer
Access to file uploaded with FileField Django
I'm trying to create a Django form with a filefield to upload a pdf based on a model.
#models.py
class ProductionRequest(models.Model):
...
contract_file = models.FileField('Contract file (PDF)', upload_to='contracts/')
...
I can…

dxtr69
- 25
- 2
- 8
2
votes
1 answer
Django multiple files in one field
I am trying to make a database using sqlite3 with a field for multiple files so that i can have a file list on mt model info page. For example if the model is student and he needs to store an unspecified number of homework files and needs to be able…

Rudra Mutalik
- 372
- 4
- 17
2
votes
1 answer
MySQL replication and Django FileField
I have MySQL replication setup, and it replicates nicely the database data. However, I also use FileField and ImageField, and have file loaded onto the FS. I probably will just use rsync to manually replicate this, but is there a better way?
I know…

OverClocked
- 1,177
- 1
- 11
- 19
2
votes
1 answer
Python Django Template cannot get name from model function
While I understood that I can call a function definition from our models, I can't seem to extract the file name of my uploaded document. Below I tried the following template format but either results from my desired output:
.html Version 1
2
votes
2 answers
Django mock unit test form filefield
I have a form that I want to unittest:
app/form.py
class MyForm(forms.Form):
file = forms.FileField()
app/test.py
class MyFormTest(TestCase):
def test_my_form(self):
file_mock = MagicMock(spec=File)
form =…

Al-Alamin
- 1,438
- 2
- 15
- 34
2
votes
1 answer
How can i process a multiple files from a file field in django?
I am trying to figure out how to process multiple files from a filefield in Django. I have figured out how to add the "multiple" attribute to the form field. What I need to do now is loop through each file and perform some logic.
I have a form with…

bgrobertson
- 48
- 1
- 7
2
votes
2 answers
Dynamic path for django FileSystemStorage
I was trying to save some files using Django FileSystemStorage. My model is as shown below
key_store = FileSystemStorage(
location='account/files/'+datetime.date.today().isoformat())
class Account(models.Model):
name =…

midhun
- 157
- 2
- 2
- 10
2
votes
1 answer
Flask-WTF Filefield value disappear after unsuccessful submit
I have form defined like this
class DogForm(Form):
birthdate = DateField(u'Birthdate', validators=[DataRequired(message=u"User correct form D.M.Y")], format='%d.%m.%Y')
image = FileField(u'Image of a dog', validators=[Optional()])
submit…

jojkos
- 121
- 1
- 6