Answer the question
In order to leave comments, you need to log in
How to load a separate image into the model?
Good afternoon.
There is this form:
class Layout(forms.Form):
img = forms.ImageField()
comment = forms.CharField(required=False, widget=forms.Textarea)
with open(os.path.join(settings.MEDIA_ROOT, 'mockup', request.FILES['img'].name), 'wb+') as file:
for chunk in request.FILES['img'].chunks():
file.write(chunk)
mockup = models.ImageField('Макет', blank=True, null=True)
d_f = File(open(c._mockup['img']['url']))
new_order.mockup.save(c._mockup['img']['name'], d_f, save=True)
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