FAQ Database Discussion Community


Stuck with nested serializer using Django Rest Framework and default user

django,api,rest,django-rest-framework,serializer
The models and serializers are described in the pastebin: http://pastebin.com/ZxzxWY7V In my database I have a user which also has a member profile and a set of credentials attached to it. Now... when I run this as is and try to pull a user using the AuthUserModelSerializer I get the...

JSON [{“non_field_errors”: [“Invalid data”]}]} Django Rest Framework

json,django,django-rest-framework,serializer
I have some serializer where I have some elements and want it to POST it when I create POST method for InvoiceDictionarySerializer. Dont have any idea how to make it works properly. Any suggestions? My code looks as follow: class InvoiceDictionaryElementSerializer(serializers.ModelSerializer): class Meta: model = InvoiceDictionaryElement fields = ( 'name',...

How to use Django JSON and GeoJSON Serializer?

python,json,django,serializer
I am relatively new to Django. I have read the documentation but I'm still having trouble getting it to work. views.py def getMarkers(request): query = request.GET zoom = query.__getitem__('zoom') fromlat = query.__getitem__('fromlat') tolat = query.__getitem__('tolat') fromlng = query.__getitem__('fromlng') tolng = query.__getitem__('tolng') querystring = coordinate.objects.filter(lat__gt=fromlat) .filter(lat__lt = tolat).filter(lon__gt = fromlng).filter(lon__lt =...

Gson serialize interface / abstract class

java,gson,serializer
If I register a JsonSerializer with an interface or abstract class like: GsonBuilder builder = new GsonBuilder() .registerTypeAdapter(MyInterface.class, new MySerializer()); Gson gson = builder.create(); MyInterface i = new MyConcreteClass(); String json = gson.toJson(i); // <--- Serializer is not invoked The serializer is simply not invoked in gson.toJson(). However, if I...

Django MultiValueDictKeyError what is it when do they occur and how can it be avoided?

python,json,django,serializer
I'm getting a MultiValueDictKeyError in my views.py on my zoom variable. When I remove the zoom variable the error falls on the variable bellow it. So I can assume that this will just follow suite for the rest of the variables. What is a MultiValueDictKeyError and how can they be...

django rest framework: set field-level error from serializer validate() method

django,django-rest-framework,serializer
I have a serializer that validates fields based on the values of other fields, In the error response I would like to show each field error as a field error as opposed to showing everything under "non_field_errors" which is what would happen if I were to raise a ValidationError in...

django-rest-framework edit data after validation

django,validation,django-rest-framework,serializer
I have a few fields on my serializer and I have overridden the validate method on serializer to do some object-level validation. The problem is after validation, I need to edit the final data before passing it to create function. Currently, I'm doing this: class MySerializer(serializers.ModelSerializer): def validate(self, attrs): #...

JSON.NET custom serialization of properties

json,json.net,serializer
I have a class looks like below public Class Sample { public string schema {get; set; } public string version {get; set; } } output i am looking for is { $schema : "some schema", version : "1.1.1.1.1" } I used below code to serialize the public class SchemaSerializer :...

why do we need to prevent Circular Object References

json.net,xmlserializer,datacontractserializer,serializer
I'm new to this. Can you please explain to me why the "Circular REference" is a bad thing, what's the bad result it may bring about?

Why `create()` method of django rest framework serializer return a value?

python-2.7,django-rest-framework,serializer
I don't understand why the create() method in DRF serializer has to return a value. E.g.: class UserSerializer(serializers.ModelSerializer): profile = ProfileSerializer() class Meta: model = User fields = ('username', 'email', 'profile') def create(self, validated_data): profile_data = validated_data.pop('profile') user = User.objects.create(**validated_data) Profile.objects.create(user=user, **profile_data) return user Would not be sufficient save User...