Hi,

I’m definitively not sure about that too.
Could you try to create a Weather instance as 
Weather.objects.create(latitude=xx, longitude=xx) and see if it works and set 
correctly automatically the latlong value, then it’s likely a DRF issue.
Otherwise, you may want to discuss that on the django user mailing list first.

Regards,
Xavier Ordoquy,
Linovia.

> Le 23 mars 2017 à 23:47, Mark Mikofski <[email protected]> a écrit :
> 
> Hi, I have a Django (1.8.5) model with a custom field that calls pre-save() 
> to evaluate the field from other model fields:
> 
> class LatLongField(models.CharField):
>     """
>     Custom field class based on :class:`~django.db.models.CharField` that
>     creates a string field from the site coordinates.
>     """
>     def pre_save(self, model_instance, add):
>         """
>         Create the lat long field the every time the model is saved.
>         """
>         # save latitude and longitude with 3 decimal places
>         value = '%.3f %.3f' % (model_instance.latitude,
>                                model_instance.longitude)
>         setattr(model_instance, self.attname, value)
>         return value
> 
> This custom field is used in a model with latitude and longitude to create a 
> string that can be "unique". The custom field is used in a unique together 
> constraint:
> 
> class Weather(models.Model):
>     latitude = models.FloatField()
>     longitude = models.FloatField()
>     header = models.CharField()
>     datatype= models.ChoiceField()
>     latlong = models.LatLongField()
> 
> If I make a model serializer no matter what I get, lat-long field is 
> required. If I exclude it from the serializer, I get no validators and an 
> integrity error exception (500 server error)
> 
> Is this a django issue or a drf issue?
> 
> 
> 
> -- 
> 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] 
> <mailto:[email protected]>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
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