but i want to do it myself.

when i write code i can improve it as much as i can. 
can anybody please tell me about my mistake please

On Monday, July 3, 2017 at 9:12:55 PM UTC+4:30, Andréas Kühne wrote:
>
> I would have a look at the easy-thumbnails plugin (
> http://easy-thumbnails.readthedocs.io/en/2.1/). It uses pillow behind the 
> scenes and it is very easy to do the cropping and everything that you need 
> and you don't need to write it yourself :-)
>
> Regards,
>
> Andréas
>
> 2017-07-03 12:09 GMT+02:00 shahab emami <royar...@gmail.com <javascript:>>
> :
>
>> hello
>>
>> i have a question and i cant find answer with search.
>>
>> i want to save cropped image in database then :
>> this is my model:
>>
>> class Photo(models.Model):
>>     file        = models.ImageField(upload_to='%Y/%m/%d', 
>> blank=True,null=True)
>>
>>
>> i have a form then user can select image and send to view like this:
>>
>> <form method="post" enctype="multipart/form-data" " >
>>     {% csrf_token %}
>>
>>   <input type="file"  id="photo_id" name="file">
>>
>>     <input type="submit" value=" send image" />
>>
>>   </form>
>>
>>
>> and in the view i have this :
>>
>> from PIL import Image
>>
>>
>> def save_photo(request):
>>
>>     _photo, created = models.Photo.objects.get_or_create(pk=1)
>>
>>     if request.method == 'POST':
>>         photo = request.FILES.get('file')
>>
>>         image = Image.open(photo)
>>
>>         cropped_image = image.crop((100, 100, 200, 200))
>>         resized_image = cropped_image.resize((200, 200), Image.ANTIALIAS)
>>         _photo.file = resized_image
>>         _photo.save()
>>
>>
>>         return HttpResponse("your image has been saved")
>>
>>
>>
>>
>>
>> but i get this error:
>>
>> 'Image' object has no attribute '_committed'
>>
>>
>>
>> i'm sure my mistake is in views.py but i dont now how to fix it. how can 
>> put resized_image that is an object of Image class to 
>> a model.
>> can you help me please?
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com <javascript:>.
>> To post to this group, send email to django...@googlegroups.com 
>> <javascript:>.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/362887c4-6b41-47e2-a9f5-f4a129b2538d%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/362887c4-6b41-47e2-a9f5-f4a129b2538d%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7be760c5-b5e3-4066-bb27-e953e829d68c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to