python - How to update with method PUT django-rest-framework -


when prompted put (update) out error

can not call .is_valid () no data = keyword argument passed when instantiating serializer instance. view:

    def get_serializer(self, *args, **kwargs):             queryset = producer.objects.get(pk=self.kwargs['pk'])             if self.request.user.is_authenticated:                 return producerserializer(queryset,                                           fields=('short_info',))              if self.request.method == 'put' or self.request.method == 'patch':                 return producerupdateserializer              else:                 return producerserializer(queryset,                                           fields=('website', 'phone', 'email', 'contacts', 'short_info'))          def get_queryset(self):             return producer.objects.filter(pk=self.kwargs['pk']) 

my serializer

 class dynamicfieldsmodelserializer(serializers.modelserializer):      def __init__(self, *args, **kwargs):         # don't pass 'fields' arg superclass         fields = kwargs.pop('fields', none)          # instantiate superclass         super(dynamicfieldsmodelserializer, self).__init__(*args, **kwargs)          if fields not none:             in fields:                 print self.fields.pop(i)   class producerserializer(dynamicfieldsmodelserializer):     tags = taglistserializerfield()     categories = serializers.stringrelatedfield(many=true)     contacts = producercontactserializer(many=true)     country = countryfield(country_dict=true)     business_type = choicesserializerfield()      class meta:         model = producer         fields = ('id', 'business_type', 'logo', 'name', 'slug', 'country', 'city',                   'street_address', 'zip', 'short_info', 'info', 'website',                   'categories', 'tags', 'contacts', 'email', 'phone')   class producerupdateserializer(serializers.modelserializer):     tags = taglistserializerfield()     categories = serializers.stringrelatedfield(many=true)      class meta:         model = producer         fields = ('id', 'business_type', 'logo', 'name', 'slug', 'country', 'city',                   'street_address', 'zip', 'short_info', 'info', 'website', 'categories', 'tags') 

when prompted put (update) out error

can not call .is_valid () no data = keyword argument passed when instantiating serializer instance.

for 1 thing, doubt get_serializer correct put. should return instance while return class.

as issue, error message pretty clear. not passing data=request.data serializer when instantiating it. documentation contains an example of how that.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -