I have a Manager fucntion that prefetches cover photo of the model.The cover_photo (Foreign key to a image model) model has a field is_verified
. Is there a way to make the cover_photo object None
if it has is_verified=False
from the manager? So that from normal user point view I can hide unverified image model contents and from admin side no restrictions.
(this manager function is for listing deities for normal user.)
The function inside my manager:
def for_deities(self):
temple_objs = self.prefetch_related(
Prefetch(
"deity_list",
queryset=TempleDeity.objects.select_related("cover_photo")
.prefetch_related(
"photo_list",
"video_list",
)
.filter(is_verified=True, site_visible=True),
# to_attr="deities_list",
),
)
# for temple_obj in temple_objs: # Unsuccessful attempt
# for deity_obj in temple_obj.deities_list:
# # pass
# if not deity_obj.cover_photo.is_verified:
# deity_obj.cover_photo = None
return temple_objs
The commented sections was my try, and it failed. What should I do to achieve this.