Add image dimensions to the API and the third image size

There has been some refactoring going on in the pinry.pins.models module.
The upload_to code has been refactored into its own function, images
have been moved to their own models - otherwise the number of fields
in the Pin model would skyrocket. Also ModelManagers have been written
to move image fetching and generating outside of models.
This commit is contained in:
Krzysztof Klimonda
2013-02-23 20:33:10 +01:00
parent 513827e128
commit e2a38f8a10
10 changed files with 189 additions and 139 deletions

View File

@@ -22,9 +22,17 @@ class UserResource(ModelResource):
class PinResource(ModelResource):
images = fields.DictField()
tags = fields.ListField()
submitter = fields.ForeignKey(UserResource, 'submitter', full=True)
def dehydrate_images(self, bundle):
images = {}
for type in ['standard', 'thumbnail', 'original']:
image_obj = getattr(bundle.obj, type, None)
images[type] = {'url': image_obj.image.url, 'width': image_obj.width, 'height': image_obj.height}
return images
class Meta:
queryset = Pin.objects.all()
resource_name = 'pin'
@@ -33,6 +41,7 @@ class PinResource(ModelResource):
'published': ['gt'],
'submitter': ['exact']
}
fields = ['submitter', 'tags', 'published', 'description', 'url']
authorization = DjangoAuthorization()
def build_filters(self, filters=None):