def create(self, validated_data): picture = validated_data.get('picture') picture_format = self.get_validate_format(str(picture)) container_mac = picture_format['container'] date_time = picture_format['datetime'] container = Container.objects.filter(identifier_mac=container_mac) if not container.exists(): trip = Trip.create(date_time, picture, container_mac, is_new=True) url = get_exif_path_url(trip.picture) trip.metadata = get_exif_dumps(url) metadata_latitude = get_exif_loads(trip.metadata)[0]['exif:GPSLatitude'] metadata_longitude = get_exif_loads(trip.metadata)[0]['exif:GPSLongitude'] trip.latitude = convert_degress_to_decimal(metadata_latitude) trip.longitude = convert_degress_to_decimal(metadata_longitude) trip.save() else: container = Container.objects.get(identifier_mac=container_mac) trip = Trip.create(date_time, picture, container, is_new=False) url = get_exif_path_url(trip.picture) trip.metadata = get_exif_dumps(url) metadata_latitude = get_exif_loads(trip.metadata)[0]['exif:GPSLatitude'] metadata_longitude = get_exif_loads(trip.metadata)[0]['exif:GPSLongitude'] trip.latitude = convert_degress_to_decimal(metadata_latitude) trip.longitude = convert_degress_to_decimal(metadata_longitude) trip.save() return validated_data
def perform_update(self, serializer): instance = serializer.save() url = get_exif_path_url(instance.picture) instance.metadata = get_exif_dumps(url) instance.save()