Answer the question
In order to leave comments, you need to log in
How can I access an attribute?
When registering, the user needs to upload his avatar. In views.py, when receiving form values, a watermark is applied to the avatar, after which all data is stored in the database. Tell me how to extract the avatar so that it can be processed later, and how to put it back processed.
When using dic(form) I do not find any attributes similar to those used in the user model.
def post(self, request):
form = ClientCreateForm(request.POST, request.FILES)
print(dir(form))
if not form.is_valid():
return HttpResponse('Client does not created!')
c = form.save(commit=False)
c.avatar = watermark_avatar(input_avatar_path = request.FILES['avatar'])
с.save()
return HttpResponse('New client is registred')
Answer the question
In order to leave comments, you need to log in
from PIL import Image
def save(self, *args, **kwargs):
super(Posts, self).save(*args, **kwargs) # Posts - модель
imag = Image.open(self.image.path) #image - поле в модели.
if imag.width > 400 or imag.height> 300: # изменение размера для примера
output_size = (400, 300)
imag.thumbnail(output_size)
imag.save(self.post_image.path)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question