Reputation: 1434
There are existing posts here which deal with the same problem as mine however, none offer a proper solution for my problem. I am working on a project with multiple models say A,B,C,D and E. Three of those have FileFields in them. I have made changes to settings.py MEDIA_ROOT and MEDIA_URL to get FileField working. It works perfectly on 2 models and saves to the proper location and everything. For the third model, the same line
models.FileField( upload_to='media/documents', null=True, blank=True)
doesn't save the file to the location. The httpd error logs are blank. This third model is an inline model. Anyone has any ideas as to why this model would suddenly 'glitch'. Below are the httpd access logs
192.168.45.139 - - [06/Aug/2018:15:50:01 +0000] "POST /admin/midb/job/3027/change/ HTTP/1.1" 302 -
192.168.45.139 - - [06/Aug/2018:15:50:01 +0000] "GET /admin/midb/job/3027/change/ HTTP/1.1" 200 205520
192.168.45.139 - - [06/Aug/2018:15:50:03 +0000] "GET /nested_admin/server-data.js HTTP/1.1" 200 288
192.168.45.139 - - [06/Aug/2018:15:50:03 +0000] "GET /admin/jsi18n/ HTTP/1.1" 200 3185
Edit: Added models. The first two 'work' while the last one doesnt. The first two are by themselves while the third model is inlined. This is being saved in Django admin.
class CustomerPDF(models.Model):
author = models.CharField(blank=False, null=False, max_length=300)
other_members = models.CharField(blank=True, null=True, max_length=250)
institute = models.CharField(blank=True, null=True, max_length=300)
cr_system = models.ForeignKey(
Job, on_delete=models.CASCADE, blank=True, null=True)
paper = models.CharField(blank=True, null=True, max_length=300)
url = models.URLField(blank=True, null=True,
max_length=300)
year = models.CharField(blank=True, null=True, max_length=150)
journal = models.CharField(blank=True, null=True, max_length=300)
tags = models.CharField(blank=True, null=True, max_length=200)
file_pdf_customer = models.FileField(
upload_to='media/documents', null=True, blank=True)
file_pdf_customer.allow_tags = True
class MarketTrends(models.Model):
author = models.CharField(blank=False, null=False, max_length=300)
institute = models.CharField(blank=True, null=True, max_length=500)
paper = models.CharField(blank=True, null=True, max_length=300)
year = models.CharField(blank=True, null=True, max_length=15)
tags = models.CharField(blank=True, null=True, max_length=200)
file_pdf_market = models.FileField(
upload_to='media/documents', null=True, blank=True)
file_pdf_market.allow_tags = True
class TripReport(models.Model):
service_name = models.ForeignKey(ServiceSupport, on_delete=models.CASCADE)
trip_description = models.CharField(
"Description", max_length=500, blank=True, null=True)
files = models.FileField(
upload_to='media/documents', null=True, blank=True)
Upvotes: 1
Views: 3071
Reputation: 96
Did you add these code in template?
<form method="post" id="myform" enctype="multipart/form-data">
Upvotes: 5