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 django-rest-framework+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to