Answer the question
In order to leave comments, you need to log in
How in django in the form of editing the field filefield to display the files already there?
Hello. The essence of the problem:
1. There is a Company model:
class Company(models.Model):
title = models.CharField(max_length=100, verbose_name=u'Название компании', blank=True)
...
class CompanyImage(models.Model):
file = models.FileField(upload_to='images/company',blank=True, null=True,verbose_name=u'Фотографии')
order = models.ForeignKey(Company, verbose_name=u'Фото компании')
class AddCompanyForm(forms.ModelForm):
files = MultiFileField(min_num=1, max_num=7, max_file_size=1024*1024*5, label=CompanyImage._meta.get_field_by_name('file')[0].verbose_name)
class Meta:
model = Company
def save(self, commit=True):
instance = super(AddCompanyForm, self).save(commit)
for each in self.cleaned_data['files']:
CompanyImage.objects.create(file=each, order=instance)
return instance
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question