I am using django-image-cropping: https://github.com/jonasundderwolf/django-image-cropping
What I am trying to achieve is simple crop by the manual. I am using 1.7.1 Django version.
models.py
class Image(models.Model):
file = models.ImageField('File', upload_to='dependencies/images/photos/')
gallery = models.ForeignKey('Gallery', related_name='images', blank=True, null=True)
cropping = ImageRatioField('file', '370x267', size_warning=True)
views.py
def photos(request):
photos = Image.objects.all()
return render_to_response('photos.html', {'photos':photos}, context_instance=RequestContext(request))
template
{% load cropping %}
{% for photo in photos %}
<img src="{% cropped_thumbnail image "cropping" %}" border="0">
{% endfor %}
error
AttributeError at /photos/
'str' object has no attribute '_meta'
Exception Location:
/venv/lib/python2.7/site-packages/image_cropping/templatetags/cropping.py in cropped_thumbnail, line 16
Python Executable:
/venv/bin/python
I researched this error and found this:
How to add attribute '_meta' to an object?
When I changed the views.py for 1 element with
'Test.objects.get()'
not
'Test.objects.all()'
test = Test.objects.get(title='test')
to test it out it cropped perfectly.
But if I want to crop all in the Image model and use the 'for loop' I have this error.
To help you more here is the part on the line 16:
cropping.py
@register.simple_tag(takes_context=True)
def cropped_thumbnail(context, instance, ratiofieldname, **kwargs):
'''
Syntax:
{% cropped_thumbnail instancename "ratiofieldname"
[scale=0.1|width=100|height=200|max_size="100x200"] [upscale=True] %}
'''
ratiofield = instance._meta.get_field(ratiofieldname)
image = getattr(instance, ratiofield.image_field) # get imagefield
if ratiofield.image_fk_field: # image is ForeignKey
# get the imagefield
image = getattr(image, ratiofield.image_fk_field)
Please help, Thank you