File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed
Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change 11from __future__ import annotations
22
3+ from contextlib import suppress
4+
35from core .models import BaseAbstractModel , BaseAbstractModelQuerySet , MarkdownField
46from django .contrib .auth import get_user_model
57from django .db import models
@@ -87,6 +89,16 @@ class Presentation(BaseAbstractModel):
8789 def __str__ (self ) -> str :
8890 return f"[{ self .type .name } ] { self .title } "
8991
92+ def active_categories (self ) -> list [PresentationCategory ]:
93+ with suppress (AttributeError ):
94+ return self ._prefetched_active_categories
95+ return list (self .categories .filter_active ())
96+
97+ def active_speakers (self ) -> list [PresentationSpeaker ]:
98+ with suppress (AttributeError ):
99+ return self ._prefetched_active_speakers
100+ return list (self .speakers .filter_active ())
101+
90102
91103class PresentationCategoryRelation (models .Model ):
92104 presentation = models .ForeignKey (Presentation , on_delete = models .CASCADE )
Original file line number Diff line number Diff line change @@ -43,8 +43,8 @@ class Meta:
4343
4444class PresentationSerializer (serializers .ModelSerializer ):
4545 image = serializers .FileField (source = "image.file" , read_only = True , allow_null = True )
46- categories = PresentationCategorySerializer (many = True , read_only = True )
47- speakers = PresentationSpeakerSerializer (many = True , read_only = True )
46+ categories = PresentationCategorySerializer (many = True , read_only = True , source = "active_categories" )
47+ speakers = PresentationSpeakerSerializer (many = True , read_only = True , source = "active_speakers" )
4848 room_schedules = RoomScheduleSerializer (source = "room_schedules_set" , many = True , read_only = True )
4949 call_for_presentation_schedules = CallForPresentationScheduleSerializer (many = True , read_only = True )
5050
You can’t perform that action at this time.
0 commit comments