Ошибка типа: объект типа RecivingObjectImages не JSON сериализуемый - PullRequest
0 голосов
/ 28 января 2020

Здравствуйте, я пытаюсь реализовать запрос select_related для обработки данных из двух таблиц RecievingObjectImages и ObjectUpdationImages

, но я постоянно зависаю на

Отладочный вывод

(Pdb)
TypeError: Object of type RecievingObjectImages is not JSON serializable
> /Users/prady/github/GIS/papli-production-PH/GisServer/reciever/views.py(77)get()
-> return HttpResponse(json.dumps({'mapped_images': mapped_images}),

Файл моделей

class RecievingObjectImages(models.Model):
    """Original and Masked Object Images"""
    name          = models.CharField(max_length = 100, unique = True, primary_key=True)
    area          = models.IntegerField()
   ........
    RCreated_date = models.DateTimeField(auto_now_add=True)
    ROwner        = models.CharField(max_length = 100)
    # agency_name   = models.CharField(max_length=100)  
    rawImage = models.ImageField(upload_to=imageNameForRawImage,)
    maskedImage = models.ImageField(upload_to=imageNameForObjectImage,)

    objects = GeoManager()

    def __str__(self):
        return self.name

    class Meta:
        verbose_name_plural = 'Object Mapping'

class ObjectUpdationImages(models.Model):
    """ Update Object Image wrt name"""
    name            = models.ForeignKey(RecievingObjectImages, on_delete=models.PROTECT, unique=True)
    ........
    is_filled       = models.BooleanField(default=True)
    checked         = models.BooleanField(default=False)

    def __str__(self):
        return str(self.name)

Просмотр файлов

class Mapping_photos_select_related(APIView):
    """Mapping all images together"""
    # breakpoint()
    def get(self, requests):
        mapped_images_qs = ObjectUpdationImages.objects.select_related('name').all()

        mapped_images = []

        for image in mapped_images_qs:
            mapped_images.append({
                'name'                  : image.name,
                'updated_image'         : image.updated_image,
                .............
                'rawImage'              : image.name.rawImage,
                'maskedImage'           : image.name.maskedImage,
        })

        # return mapped_images
        return HttpResponse(json.dumps({'mapped_images': mapped_images}),
                    content_type='application/json; charset=utf8')


...