Skip to content

Instantly share code, notes, and snippets.

View kieranm's full-sized avatar
📆
Building a Calendar

Kieran McHugh kieranm

📆
Building a Calendar
View GitHub Profile
@AndrewJHart
AndrewJHart / resources.py
Last active December 28, 2015 09:29
Override django-tastypie hydrate_FIELD to remove/delete JSON field(s) (related field in this instance) for tastypie resource on PUT request only before its converted to object and saved.
def hydrate_device(self, bundle):
"""
override hydrate method for incoming bundle hydrate is done on a per field basis (really cool)
so this allows to override only the one (related field) and to strip the JSON data from the PUT
request thus allowing PUT request to go through successfully. NOTE: Only for PUT requests - we need
this data for POST or else the related field (device) wont be created
Issue stems from the relation - DeviceSettings has one-to-one to Device, DeviceSettings stores meta
data and other stuff about the device w/o interferring with the original device model and allowing
separation of concerns to make the Device and Service models work as standalone app for apns/gcm. Thus,
unique foreign key constraint on the Device model w/ APNService FK & due to one way relationship