import - service_area in organization serializer api
This commit is contained in:
@@ -7,7 +7,7 @@ ENV_NAME=DEV
|
|||||||
# Database secrets
|
# Database secrets
|
||||||
DB_HOST=31.7.78.133
|
DB_HOST=31.7.78.133
|
||||||
DB_PORT=14352
|
DB_PORT=14352
|
||||||
DB_NAME=Production
|
DB_NAME=Development
|
||||||
DB_USERNAME=postgres
|
DB_USERNAME=postgres
|
||||||
DB_PASSWORD=pfLIVXupbDetvFMt2gUvxLXUL9b4HIOHaPcKXsBEZ1i8zl0iLUjmhUfXlGfJKcTV
|
DB_PASSWORD=pfLIVXupbDetvFMt2gUvxLXUL9b4HIOHaPcKXsBEZ1i8zl0iLUjmhUfXlGfJKcTV
|
||||||
|
|
||||||
|
|||||||
@@ -260,9 +260,14 @@ class OrganizationSerializer(serializers.ModelSerializer):
|
|||||||
'national_unique_id',
|
'national_unique_id',
|
||||||
'company_code',
|
'company_code',
|
||||||
'field_of_activity',
|
'field_of_activity',
|
||||||
'free_visibility_by_scope'
|
'free_visibility_by_scope',
|
||||||
|
'service_area'
|
||||||
]
|
]
|
||||||
extra_kwargs = {}
|
extra_kwargs = {
|
||||||
|
'service_area': {
|
||||||
|
'required': False
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def validate(self, attrs):
|
def validate(self, attrs):
|
||||||
"""
|
"""
|
||||||
@@ -346,6 +351,14 @@ class OrganizationSerializer(serializers.ModelSerializer):
|
|||||||
representation['bank_account'] = BankAccountSerializer(
|
representation['bank_account'] = BankAccountSerializer(
|
||||||
instance.bank_information.all(), many=True
|
instance.bank_information.all(), many=True
|
||||||
).data
|
).data
|
||||||
|
|
||||||
|
if instance.service_area:
|
||||||
|
representation['service_area'] = [
|
||||||
|
{
|
||||||
|
'id': city.id,
|
||||||
|
'name': city.name,
|
||||||
|
} for city in instance.service_area.all()
|
||||||
|
]
|
||||||
return representation
|
return representation
|
||||||
|
|
||||||
def update(self, instance, validated_data):
|
def update(self, instance, validated_data):
|
||||||
@@ -362,6 +375,10 @@ class OrganizationSerializer(serializers.ModelSerializer):
|
|||||||
instance.free_visibility_by_scope
|
instance.free_visibility_by_scope
|
||||||
)
|
)
|
||||||
instance.save()
|
instance.save()
|
||||||
|
|
||||||
|
if validated_data.get('service_area'):
|
||||||
|
instance.service_area.clear()
|
||||||
|
instance.service_area.add(*(validated_data.get('service_area')))
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user