Beispiel #1
0
class PurchaseSerializer(serializers.ModelSerializer):

    canteen = serializers.PrimaryKeyRelatedField(read_only=True)
    invoice_file = Base64FileField(required=False, allow_null=True)
    price_ht = serializers.DecimalField(localize=True,
                                        max_digits=20,
                                        decimal_places=2)

    class Meta:
        model = Purchase
        fields = (
            "id",
            "creation_date",
            "modification_date",
            "canteen",
            "date",
            "description",
            "provider",
            "category",
            "characteristics",
            "price_ht",
            "invoice_file",
            "local_definition",
        )
        read_only_fields = ("id", )

    def create(self, validated_data):
        if "canteen" not in validated_data:
            return super().create(validated_data)

        validated_data["canteen_id"] = validated_data.pop("canteen").id
        return super().create(validated_data)
Beispiel #2
0
class ExperimentVideoSerializer(serializers.ModelSerializer):
    video = Base64FileField()
    id = serializers.IntegerField(required=False)

    class Meta:
        model = ExperimentVideo
        fields = ('video', 'label', 'copyright', 'id')
Beispiel #3
0
class ExperimentVideoFastSerializer(serializers.Serializer):
    """
    Serializer to be used in retrieval actions. By bypassing
    the overhead of the ModelSerializer it is significantly
    faster : https://hakibenita.com/django-rest-framework-slow
    """
    video = Base64FileField()
    id = serializers.IntegerField(required=False)
    label = serializers.CharField()
    copyright = serializers.CharField()
Beispiel #4
0
class AgencyRequestKYBPSerializer(serializers.ModelSerializer):

    #ag_detail_id = serializers.PrimaryKeyRelatedField(queryset=AgencyRequestAGDetail.objects.all())  #AgencyRequestAGDetailSerializer(many=True)
    resi_city = serializers.PrimaryKeyRelatedField(
        queryset=CityMaster.objects.all())
    resi_state = serializers.PrimaryKeyRelatedField(
        queryset=StateMaster.objects.all())

    busi_city = serializers.PrimaryKeyRelatedField(
        queryset=CityMaster.objects.all())
    busi_state = serializers.PrimaryKeyRelatedField(
        queryset=StateMaster.objects.all())

    ag_maritial_id = serializers.PrimaryKeyRelatedField(
        queryset=MaritialStatusMaster.objects.all())

    db_dept = serializers.PrimaryKeyRelatedField(
        queryset=DepartmentMaster.objects.all())

    db_desig = serializers.PrimaryKeyRelatedField(
        queryset=DesignationMaster.objects.all())
    db_relation = serializers.PrimaryKeyRelatedField(
        queryset=RealtionMaster.objects.all())
    db_city = serializers.PrimaryKeyRelatedField(
        queryset=CityMaster.objects.all())
    add_proof_type = serializers.PrimaryKeyRelatedField(
        queryset=AddressProofMaster.objects.all())

    Agency_Child_set = Agency_ChildSerializer(many=True)
    Agency_OtherNewsPaper_set = Agency_OtherNewsPaperSerializer(many=True)

    pan_copy = Base64FileField(allow_null=True, required=False)
    add_proof_copy = Base64FileField(allow_null=True, required=False)
    bank_copy = Base64FileField(allow_null=True, required=False)

    class Meta:
        model = AgencyRequestKYBP
        # fields = '__all__'
        fields = (
            'ag_gender',
            'ag_title',
            'first_name',
            'middle_name',
            'last_name',
            'agency_name',
            'resi_houseno',
            'resi_building',
            'resi_street',
            'resi_city',
            'resi_state',
            'resi_pincode',
            'resi_mono',
            'resi_watsup',
            'resi_email',
            'busi_houseno',
            'busi_building',
            'busi_street',
            'busi_city',
            'busi_state',
            'busi_pincode',
            'busi_mono',
            'busi_watsup',
            'busi_email',
            'ag_religion',
            'ag_dob',
            'ag_maritial_id',
            'spouse_name',
            'spouse_dob',
            'ag_marrige_ani',
            'no_of_children',
            'father_name',
            'father_dob',
            'mother_name',
            'mother_dob',
            'brother_name',
            'brother_dob',
            'sister_name',
            'sister_dob',
            'nominee_name',
            'nominee_relation',
            'other_nespaper_count',
            'bank_holder_name',
            'bank_acc_no',
            'bank_name_branch',
            'bank_address',
            'bank_IFSC',
            'GSTIN',
            'ag_db_relative',
            'db_gender',
            'db_fullname',
            'db_empid',
            'db_dept',
            'db_desig',
            'db_relation',
            'db_city',
            'pan_no',
            'pan_copy',
            'add_proof_type',
            'add_proof_no',
            'add_proof_copy',
            'bank_copy_type',
            'bank_copy',
            'Agency_Child_set',
            'Agency_OtherNewsPaper_set',
        )

    def create(self, validated_data):

        resi_city = validated_data.pop(
            'resi_city'
        )  #serializers.PrimaryKeyRelatedField(queryset=CityMaster.objects.all())
        resi_state = validated_data.pop(
            'resi_state'
        )  #serializers.PrimaryKeyRelatedField(queryset=StateMaster.objects.all())

        busi_city = validated_data.pop(
            'busi_city'
        )  #serializers.PrimaryKeyRelatedField(queryset=CityMaster.objects.all())
        busi_state = validated_data.pop(
            'busi_state'
        )  #serializers.PrimaryKeyRelatedField(queryset=StateMaster.objects.all())

        ag_maritial_id = validated_data.pop(
            'ag_maritial_id'
        )  #serializers.PrimaryKeyRelatedField(queryset=MaritialStatusMaster.objects.all())

        db_dept = validated_data.pop(
            'db_dept'
        )  #serializers.PrimaryKeyRelatedField(queryset=DepartmentMaster.objects.all())

        db_desig = validated_data.pop(
            'db_desig'
        )  #serializers.PrimaryKeyRelatedField(queryset=DesignationMaster.objects.all())
        db_relation = validated_data.pop(
            'db_relation'
        )  #serializers.PrimaryKeyRelatedField(queryset=RealtionMaster.objects.all())
        db_city = validated_data.pop(
            'db_city'
        )  #serializers.PrimaryKeyRelatedField(queryset=CityMaster.objects.all())
        add_proof_type = validated_data.pop(
            'add_proof_type'
        )  #serializers.PrimaryKeyRelatedField(queryset=AddressProofMaster.objects.all())

        Agency_Child_validated_data = validated_data.pop('Agency_Child_set')
        Agency_OtherNewsPaper_validated_data = validated_data.pop(
            'Agency_OtherNewsPaper_set')

        AGKYBP = AgencyRequestKYBP.objects.create(
            add_proof_type=add_proof_type,
            db_city=db_city,
            db_relation=db_relation,
            db_desig=db_desig,
            db_dept=db_dept,
            ag_maritial_id=ag_maritial_id,
            busi_state=busi_state,
            busi_city=busi_city,
            resi_city=resi_city,
            resi_state=resi_state,
            **validated_data)

        Agency_Child_set_serializer = self.fields['Agency_Child_set']
        for each in Agency_Child_validated_data:
            each['kybp_id'] = AGKYBP
            #each['reason'] = validated_data.pop('reason')
        AG_Agency_Child = Agency_Child_set_serializer.create(
            Agency_Child_validated_data)

        Agency_OtherNewsPaper_set_serializer = self.fields[
            'Agency_OtherNewsPaper_set']
        for each in Agency_OtherNewsPaper_validated_data:
            each['kybp_id'] = AGKYBP
            #each['reason'] = validated_data.pop('reason')
        AG_Agency_OtherNewsPaper = Agency_OtherNewsPaper_set_serializer.create(
            Agency_OtherNewsPaper_validated_data)

        return AGKYBP