@@ -237,10 +237,24 @@ def get_can_mentor_on(self, user: ProjectUser) -> list[dict]:
237237
238238
239239class PeopleGroupLocationSerializer (BaseLocationSerializer ):
240+
240241 class Meta (BaseLocationSerializer .Meta ):
241242 model = PeopleGroupLocation
242243
243244
245+ class PeopleGroupLocationRelated (serializers .RelatedField ):
246+ def get_queryset (self ):
247+ return PeopleGroupLocation .objects .all ()
248+
249+ def to_representation (self , instance : PeopleGroupLocation ) -> dict :
250+ return PeopleGroupLocationSerializer (instance = instance ).data
251+
252+ def to_internal_value (self , element : dict ) -> PeopleGroupLocation :
253+ if element .get ("pk" ):
254+ return PeopleGroupLocation .objects .get (pk = element ["pk" ])
255+ return PeopleGroupLocation (** element )
256+
257+
244258class PeopleGroupSuperLightSerializer (
245259 AutoTranslatedModelSerializer , serializers .ModelSerializer
246260):
@@ -478,7 +492,7 @@ class PeopleGroupSerializer(
478492 child = serializers .IntegerField (min_value = 1 , max_value = 17 ),
479493 required = False ,
480494 )
481- location = PeopleGroupLocationSerializer ( )
495+ location = PeopleGroupLocationRelated ( required = False , allow_null = True )
482496
483497 def get_hierarchy (self , obj : PeopleGroup ) -> list [dict [str , str | int ]]:
484498 request = self .context .get ("request" )
@@ -540,7 +554,11 @@ def validate_parent(self, value):
540554 def create (self , validated_data ):
541555 team = validated_data .pop ("team" , {})
542556 featured_projects = validated_data .pop ("featured_projects" , [])
543- tags = validated_data .pop ("tags" , [])
557+ location = validated_data .pop ("location" , {})
558+
559+ if location :
560+ location .save ()
561+ validated_data ["id" ] = location
544562
545563 people_group = super (PeopleGroupSerializer , self ).create (validated_data )
546564 PeopleGroupAddTeamMembersSerializer ().create (
@@ -549,23 +567,25 @@ def create(self, validated_data):
549567 PeopleGroupAddFeaturedProjectsSerializer ().create (
550568 {"people_group" : people_group , "featured_projects" : featured_projects }
551569 )
552-
553- people_group .tags .set (tags )
554570 return people_group
555571
556572 def update (self , instance , validated_data ):
557573 validated_data .pop ("team" , {})
558574 validated_data .pop ("featured_projects" , [])
559- tags = validated_data .pop ("tags" , [])
575+ location = validated_data .pop ("location" )
576+
577+ if not location and getattr (instance , "location" , None ):
578+ instance .location .delete ()
579+ validated_data ["location" ] = None
580+ elif location :
581+ location .save ()
582+ validated_data ["location" ] = location
583+
560584 people_group = super (PeopleGroupSerializer , self ).update (
561585 instance , validated_data
562586 )
563- people_group .tags .set (tags )
564587 return people_group
565588
566- def save (self , ** kwargs ):
567- return super ().save (** kwargs )
568-
569589 class Meta :
570590 model = PeopleGroup
571591 read_only_fields = ["is_root" , "slug" , "modules" ]
0 commit comments