Exemplo n.º 1
0
class PoBoxAddressSerializer(serializers.HyperlinkedModelSerializer):
    type = TypeField()

    class Meta:
        model = PoBoxAddress
        fields = ('type', 'url', 'country', 'city',
                  'state_or_province', 'locality', 'box_number',)
Exemplo n.º 2
0
class StaffSerializer(serializers.HyperlinkedModelSerializer):
    type = TypeField()
    party = PartyRelatedField()

    class Meta:
        model = Staff
        fields = ('type', 'url', 'company', 'party')
Exemplo n.º 3
0
class DeviceSerializer(serializers.HyperlinkedModelSerializer):
    type = TypeField()

    class Meta:
        model = Structure
        fields = ('type', 'url', 'start_date', 'end_date',
                  'physical_object_type', 'make')
Exemplo n.º 4
0
class TenderTypeSerializer(serializers.HyperlinkedModelSerializer):
    type = TypeField()

    class Meta:
        model = TenderType
        fields = ('type', 'url', 'valid_from', 'valid_to', 'name',
                  'description', )
Exemplo n.º 5
0
class TenderSerializer(serializers.HyperlinkedModelSerializer):
    type = TypeField()

    class Meta:
        model = Tender
        fields = ('type', 'url', 'sale', 'tender_type', 'amount',
                  'reference', )
Exemplo n.º 6
0
class UrbanPropertyAddressSerializer(serializers.HyperlinkedModelSerializer):
    type = TypeField()

    class Meta:
        model = UrbanPropertyAddress
        fields = ('type', 'url', 'country', 'city', 'state_or_province', 'locality', 'postcode', 'street_name', 'street_number_first',
                  'street_number_first_suffix', 'street_number_last', 'street_number_last_suffix', 'street_suffix', 'street_type')
Exemplo n.º 7
0
class SaleItemSerializer(serializers.HyperlinkedModelSerializer):
    type = TypeField()

    class Meta:
        model = SaleItem
        fields = ('type', 'url', 'sale', 'product', 'amount',
                  'discount','promotion' )
Exemplo n.º 8
0
class OwnerSerializer(serializers.HyperlinkedModelSerializer):
    type = TypeField()
    party = PartyRelatedField()

    class Meta:
        model = Owner
        fields = ('type', 'url', 'party')
Exemplo n.º 9
0
class PromotionSerializer(serializers.HyperlinkedModelSerializer):
    type = TypeField()

    class Meta:
        model = Promotion
        fields = ('type', 'url', 'valid_from', 'valid_to', 'name',
                  'description', 'categories', 'products', 'customers')
Exemplo n.º 10
0
class IdentificationSerializer(serializers.HyperlinkedModelSerializer):
    type = TypeField()
    party = PartyRelatedField()

    class Meta:
        model = Identification
        fields = ('type', 'url', 'identification_type', 'number', 'party')
Exemplo n.º 11
0
class CustomerAccountSerializer(serializers.HyperlinkedModelSerializer):
    type = TypeField()

    class Meta:
        model = CustomerAccount
        fields = ('type', 'url', 'customer', 'account_number', 'account_status',
                  'account_type', 'name', 'pin', 'credit_limit', 'customer_account_contact',)
Exemplo n.º 12
0
class GenericPartyRoleSerializer(serializers.HyperlinkedModelSerializer):
    type = TypeField()
    telephonenumbers = TelephoneNumberSerializer(many=True, read_only=True)

    class Meta:
        model = GenericPartyRole
        fields = ('type', 'url', 'valid_from', 'valid_to', 'name',
                  'telephonenumbers')
Exemplo n.º 13
0
class ProductOfferingSerializer(serializers.HyperlinkedModelSerializer):
    type = TypeField()

    class Meta:
        model = ProductOffering
        fields = ('type', 'url', 'valid_from', 'valid_to', 'name',
                  'description', 'sku', 'categories', 'retail_price',
                  'supplier', 'buyer')
Exemplo n.º 14
0
class LoyaltySchemeSerializer(serializers.HyperlinkedModelSerializer):
    type = TypeField()
    
    class Meta:
        model = LoyaltyScheme
        fields = ('type', 'url', 'name' )  

                     
Exemplo n.º 15
0
class RetailChannelSerializer(serializers.HyperlinkedModelSerializer):
    type = TypeField()

    class Meta:
        model = RetailChannel
        fields = ('type', 'url', 'name',)
                  
                  
          
Exemplo n.º 16
0
class SaleSerializer(serializers.HyperlinkedModelSerializer):
    type = TypeField()

    class Meta:
        model = Sale
        fields = ('type', 'url', 'channel', 'store', 'datetime', 'docket_number',
                  'total_amount', 'total_amount_excl', 'total_discount', 'total_tax',
                  'customer', 'account', 'identification', 'promotion','till', 'staff', 
                  'price_channel', 'price_calculation', 'tenders','sale_items',)
Exemplo n.º 17
0
class TelephoneNumberSerializer(serializers.HyperlinkedModelSerializer):
    type = TypeField()
    party_role = serializers.HyperlinkedRelatedField(
        view_name='genericpartyrole-detail',
        queryset=GenericPartyRole.objects.all())

    class Meta:
        model = TelephoneNumber
        fields = ('type', 'url', 'party_role', 'number')
Exemplo n.º 18
0
class VehicleSerializer(serializers.HyperlinkedModelSerializer):
    type = TypeField()
    make = OrganisationSerializer()

    class Meta:
        model = Vehicle
        fields = ('type', 'url', 'start_date', 'end_date',
                  'physical_object_type', 'make', 'series', 'model', 'year',
                  'engine_capacity', 'engine_type', 'body_style', 'doors',
                  'weight', 'axles')
Exemplo n.º 19
0
class OrganisationSerializer(serializers.HyperlinkedModelSerializer):
    type = TypeField()

    class Meta:
        model = Organisation
        fields = (
            'type',
            'url',
            'party_user',
            'name',
        )
Exemplo n.º 20
0
class CustomerAccountContactSerializer(serializers.HyperlinkedModelSerializer):
    type = TypeField()
    party = GenericRelatedField( many=False,
        serializer_dict={ 
            Individual: IndividualSerializer(),
            Organisation: OrganisationSerializer(),
        })

    class Meta:
        model = CustomerAccountContact
        fields = ('type', 'url', 'party', 'customeraccount_set')
Exemplo n.º 21
0
class BuyerSerializer(serializers.HyperlinkedModelSerializer):
    party = PartyRelatedField()
    type = TypeField()

    class Meta:
        model = Buyer
        fields = (
            'type',
            'url',
            'party',
        )

    def create(self, validated_data):
        return Buyer.objects.create(**validated_data)
Exemplo n.º 22
0
class ProductCategorySerializer(serializers.HyperlinkedModelSerializer):
    type = TypeField()

    class Meta:
        model = ProductCategory
        fields = (
            'type',
            'url',
            'valid_from',
            'valid_to',
            'parent',
            'level',
            'name',
            'description',
        )
Exemplo n.º 23
0
class IndividualSerializer(serializers.HyperlinkedModelSerializer):
    type = TypeField()

    gender = serializers.ChoiceField(choices=GENDER_CHOICES,
                                     required=False,
                                     allow_blank=True)
    marital_status = serializers.ChoiceField(choices=MARITAL_STATUS_CHOICES,
                                             required=False,
                                             allow_blank=True)

    class Meta:
        model = Individual
        fields = ('type', 'url', 'party_user', 'name', 'given_names',
                  'family_names', 'middle_names', 'form_of_address', 'gender',
                  'legal_name', 'marital_status', 'nationality',
                  'place_of_birth')
Exemplo n.º 24
0
class CustomerSerializer(serializers.HyperlinkedModelSerializer):
    #party = GenericRelatedField( many=False, serializer_dict={
    #        Individual: IndividualSerializer(),
    #        Organisation: OrganisationSerializer(),
    #    })
    party = PartyRelatedField()
    type = TypeField()

    class Meta:
        model = Customer
        fields = ('type', 'url', 'customer_number',
                  'customer_status', 'party', 'customeraccount_set')

    def create(self, validated_data):
        validated_data.pop('customeraccount_set')
        print( validated_data )
        return Customer.objects.create(**validated_data)
Exemplo n.º 25
0
class SupplierSerializer(serializers.HyperlinkedModelSerializer):
    #party = GenericRelatedField( many=False, serializer_dict={
    #        Individual: IndividualSerializer(),
    #        Organisation: OrganisationSerializer(),
    #    })
    party = PartyRelatedField()
    type = TypeField()

    class Meta:
        model = Supplier
        fields = (
            'type',
            'url',
            'party',
        )

    def create(self, validated_data):
        return Supplier.objects.create(**validated_data)
Exemplo n.º 26
0
class GenericHyperlinkedSerializer(serializers.HyperlinkedModelSerializer):

    """
        Serializer for models with generic relations.
        Includes a type field to allow GenericRelatedFields specified in the serializer to know how to serialize correctly.
        Derived from hyperlinked serializer and the url field must be present on the serializer
    """
    type = TypeField()

    def create(self, validated_data):
        # Remove generic fields from validated data and add to separate dict
        related = {}
        for field in self._fields.keys():
            if type(self._fields[field]) == serializers.ManyRelatedField:
                if type(self._fields[field].child_relation) == GenericRelatedField:
                    related[field] = validated_data.pop(field)

        # Create instance of serializers Meta.model
        instance = self.Meta.model.objects.create(**validated_data)

        # For all related fields attach the listed objects
        for field in related.keys():
            for object in related[field]:
                attr = getattr(instance, field)
                attr.add(object)

        return instance

    def update(self, instance, validated_data):

        # Create a dict of updatable fields
        fields = {}
        generics = {}
        for field in self._fields.keys():
            # Exclude read only fields
            if not self._fields[field].read_only:
                if type(self._fields[field]) != serializers.ManyRelatedField:
                    fields[field] = self._fields[field]
                else:
                    # Exclude generics but add to separate dict
                    if type(self._fields[field].child_relation) != GenericRelatedField:
                        fields[field] = self._fields[field]
                    else:
                        generics[field] = self._fields[field]

        # Set all valid attributes of the instance to the validated data
        for field in fields.keys():
            setattr(instance, field, validated_data.get(
                field, getattr(instance, field)))

        # Add any new generic relations
        for generic_attr in generics.keys():
            attr = getattr(instance, generic_attr)
            attr_objects = list(attr.all())
            for object in validated_data.get(generic_attr, getattr(instance, generic_attr)):
                if object not in attr_objects:
                    # If the object is not in the list of existing generic
                    # relations then add it
                    attr.add(object)
                else:
                    # If the object is already related then remove it from the
                    # list so we end up with a list of missing generic
                    # relations
                    attr_objects.remove(object)

            # Remove any missing generic relations if not a partial update (PUT
            # but not PATCH)
            if not self.partial:
                for object in attr_objects:
                    attr.remove(object)

        instance.save()
        return instance
Exemplo n.º 27
0
class PhysicalResourceSerializer(serializers.HyperlinkedModelSerializer):
    type = TypeField()

    class Meta:
        model = PhysicalResource
        fields = ('type', 'url', 'usage_state', 'name','owner','serial_number','power_state',)
Exemplo n.º 28
0
class CitySerializer(serializers.HyperlinkedModelSerializer):
    type = TypeField()

    class Meta:
        model = City
        fields = ('type', 'url', 'code', 'name', 'country')
Exemplo n.º 29
0
class AbsoluteLocalLocationSerializer(serializers.HyperlinkedModelSerializer):
    type = TypeField()

    class Meta:
        model = AbsoluteLocalLocation
        fields = ('type', 'url', 'name', 'x', 'y', 'z', )
Exemplo n.º 30
0
class IdentificationTypeSerializer(serializers.HyperlinkedModelSerializer):
    type = TypeField()

    class Meta:
        model = IdentificationType
        fields = ('type', 'url', 'name')