Skip to content

Instantly share code, notes, and snippets.

@andybak
Forked from anonymous/models.py
Created April 10, 2014 17:27
Show Gist options
  • Save andybak/10404406 to your computer and use it in GitHub Desktop.
Save andybak/10404406 to your computer and use it in GitHub Desktop.
DRF, Getters Setters, PolymorphicModel
class MyModel(PolymorphicModel):
@property
def driver(self):
if self.is_departure: return self.delivery_driver
else: return self.collection_driver
@driver.setter
def driver(self, value):
if self.is_departure: self.delivery_driver = value
else self.collection_driver = value
class MyModelSerializer(serializers.ModelSerializer):
driver = UserSerializer()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment