mirror of
https://github.com/pinry/pinry.git
synced 2025-11-13 16:45:41 +01:00
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:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user