def get(_, lang, image_id): delete_flag = True image_model = Image() category_model = Category() if lang == 'ja': topic_model = Topic() introduction_model = Introduction() else: topic_model = TopicEn() introduction_model = IntroductionEn() try: image = image_model.get_by_image_id(image_id) topic_use_flag, topic_use_posts = topic_model.is_use_image( image.image_url, image.id) if topic_use_flag is True: delete_flag = False introduction_use_flag, introduction_use_posts = \ introduction_model.is_use_image(image.image_url) if introduction_use_flag is True: delete_flag = False category_use_flag, category_use_posts = category_model.is_use_image( image.image_url) if category_use_flag is True: delete_flag = False use_posts = ( topic_use_posts + category_use_posts + introduction_use_posts ) def get_unique_list(seq): seen = [] return [x for x in seq if x not in seen and not seen.append(x)] use_posts = get_unique_list(use_posts) return JsonResponse({ 'status': 200, 'delete_flag': delete_flag, 'use_posts': use_posts, }, status=200) except Exception as e: return JsonResponse({ 'status': 500, 'message': 'Exception Error ' + str(e) }, status=500)