Пример #1
0
 def to_representation(self, instance):
     data = super().to_representation(instance)
     data['sections'] = SectionSerializer(instance=instance.sections.all(),
                                          many=True,
                                          context=self.context).data
     if instance.project_phase:
         data['project'] = ProjectSerializer(
             instance=instance.project_phase.project,
             context=self.context).data
     else:
         data['project'] = None
     return data
Пример #2
0
 def to_representation(self, instance):
     data = super().to_representation(instance)
     data['sections'] = SectionSerializer(instance=instance.sections.all(),
                                          many=True,
                                          context=self.context).data
     return data
Пример #3
0
def test_section_serializer(random_hearing):
    section = random_hearing.sections.first()
    section.type = SectionType.objects.get(identifier=InitialSectionType.PART)
    data = SectionSerializer(instance=section).data
    assert data["type"] == InitialSectionType.PART