Hi Xavier,

Thanks for your quick reply. I had to rush off and I didn't get to finish 
the post. Sorry!

Yes, I can make model objects and save them to the database using w = 
Weather(latitude=x, longitude=y, header="blah", datatype=3) and w.save().

The issue only occurs when I test the unique together constraint by posting 
a duplicate.

If the serializer looks like this:

class WeatherSerializer(serializers.ModelSerializer):
    """weather serializer"""

    class Meta:
        model = Weather
        exclude = ('lat_long',)


then I can post new records fine. But if I try to post a duplicate that's 
when I get the integrity error, and since the validator is missing from the 
serializer, the server says 500.

If I remove the line `exclude = ('lat_long')` then the serializer _does_ 
have the `UniqueTogetherValidator` which I can see in a Django shell as 
WeatherSerializer().validators

However, now if I try to post a duplicate, instead of getting 500, I do get 
400, good, but the message is not "non_field_errors": ["The fields 
lat_long, header, datatype must make a unique set."], instead I get "lat_long": 
["This field is required."]

* I realize I should/could use DecimalField for latitude and longitude and 
that would resolve my problem.
* I tried using HiddenField but couldn't get it to make the lat_long value 
without knowing the serializer object a priori
* SerializerMethodField with get_lat_long(obj) method didn't work either

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to