Exemple #1
0
    def dehydrate(self, bundle):
        """Serializing. GET method."""
        lonlat = GEOSGeometry(bundle.data['coordinates'], srid=32140)
        bundle.data['coordinates'] = list(lonlat.get_coords())

        # get profile pict
        if bundle.obj.profile_image_id is not None:
            profile_pict = Image.objects.get(pk=bundle.obj.profile_image_id)

        if profile_pict is not None:
            bundle.data['profile_image'] = profile_pict.thumbnail.url

        # get images
        images = Image.objects.filter(shelter_id__exact=bundle.obj.id)
        if images is None:
            return bundle

        image_urls = []
        thumbnail_urls = []

        for image in images:
            image_urls.append(image.image.url)
            thumbnail_urls.append(image.thumbnail.url)
        bundle.data['images'] = image_urls
        bundle.data['thumbnails'] = thumbnail_urls

        return bundle