class TransactionRecipientCountrySerializer(DynamicFieldsModelSerializer): country = CountrySerializer(fields=('url', 'code', 'name')) class Meta: model = models.TransactionRecipientCountry fields = ( 'id', 'country', )
class TransactionRecipientCountrySerializer(DynamicFieldsModelSerializer): id = serializers.HiddenField(default=None) country = CountrySerializer(fields=('url', 'code', 'name')) class Meta: model = models.TransactionRecipientCountry fields = ( 'id', 'country', )
class RecipientCountrySerializer(DynamicFieldsModelSerializer): country = CountrySerializer(fields=('url', 'code', 'name')) percentage = serializers.DecimalField(max_digits=5, decimal_places=2, coerce_to_string=False) # vocabulary = VocabularySerializer() class Meta: model = iati.models.ActivityRecipientCountry fields = ( 'country', 'percentage', )
class CitySerializer(DynamicFieldsModelSerializer): url = serializers.HyperlinkedIdentityField(view_name='cities:city-detail') country = CountrySerializer(fields=('url', 'code', 'name')) location = GeometryField() class Meta: model = geodata.models.City fields = ( 'url', 'id', 'geoname_id', 'name', 'country', 'location', 'is_capital', )
class TransactionRecipientCountrySerializer( api.transaction.serializers.TransactionRecipientCountrySerializer): country = CountrySerializer(fields=('code', 'name'))
class OrganisationRecipientCountryBudgetSerializer(ModelSerializerNoValidation ): organisation = serializers.CharField(write_only=True) value = ValueSerializer(source='*') status = CodelistSerializer() # because we want to validate in the validator instead period_start = serializers.CharField() period_end = serializers.CharField() recipient_country = CountrySerializer(source="country", fields=('url', 'code', 'name')) budget_lines = RecipientCountryBudgetLineSerializer( many=True, source="recipientcountrybudgetline_set", required=False) class Meta: model = org_models.RecipientCountryBudget fields = ( 'organisation', 'id', 'status', 'recipient_country', 'period_start', 'period_end', 'value', 'budget_lines', ) def validate(self, data): organisation = get_or_raise(org_models.Organisation, data, 'organisation') validated = validators.organisation_recipient_country_budget( organisation, data.get('status', {}).get('code'), data.get('country', {}).get('code'), data.get('period_start'), data.get('period_end'), data.get('value'), data.get('currency').get('code'), data.get('value_date'), ) return handle_errors(validated) def create(self, validated_data): organisation = validated_data.get('organisation') instance = org_models.RecipientCountryBudget.objects.create( **validated_data) organisation.modified = True organisation.save() return instance def update(self, instance, validated_data): organisation = validated_data.get('organisation') update_instance = org_models.RecipientCountryBudget(**validated_data) update_instance.id = instance.id update_instance.save() organisation.modified = True organisation.save() return update_instance
class RecipientCountrySerializer(serializers.RecipientCountrySerializer): country = CountrySerializer(fields=('code', 'name'))