Closed Mohamed-Kaizen closed 4 years ago
can i send data when accept_pk=True
accept_pk=True
class AddressSerializer(DynamicFieldsMixin, serializers.ModelSerializer): """Serializer for address model.""" class Meta: """Meta data.""" model = models.Address fields = ("name", "country", "state") class WareHouseSerializer2(DynamicFieldsMixin, NestedModelSerializer): """Serializer for warehouse model.""" id = serializers.UUIDField(read_only=True) address = NestedField(AddressSerializer, accept_pk=True) remark = serializers.CharField(required=False) created_at = serializers.DateTimeField(read_only=True) updated_at = serializers.DateTimeField(read_only=True) class Meta: """Meta data.""" model = models.WareHouse fields = "__all__"
views.py
class WareHouseViewSet(viewsets.ModelViewSet): """ViewSet for WareHouse model.""" queryset = models.WareHouse.objects.all() serializer_class = serializers.WareHouseSerializer filter_backends = (OrderingFilter, SearchFilter) ordering = ("-created_at",) ordering_fields = ("created_at", "updated_at") lookup_field = "id"
when sending with pk it work
POST api/warehouse/
{ "address": "c079d70e-eadd-4e20-b90f-2ecc6e28683b", "remark": "string", "code": "string", "name": "string", "is_bin_mandatory": true }
it's work but when sending data of the address
"address": { "name": "string", "country": "AF", "state": "string" }, "remark": "string", "code": "string", "name": "string", "is_bin_mandatory": true }
Response:
{ "address": [ "“{'name': 'string', 'country': 'AF', 'state': 'string'}” is not a valid UUID." ] }
in other word drf-flex-fields let you do that , so is there way to do that with django-restql ?
drf-flex-fields
django-restql
This is a good feature to have, someone requested it here(#187 ) too, we are definitely going to implement this.
can i send data when
accept_pk=True
views.py
when sending with pk it work
POST api/warehouse/
it's work but when sending data of the address
POST api/warehouse/
Response:
in other word
drf-flex-fields
let you do that , so is there way to do that withdjango-restql
?