Skip to content

Instantly share code, notes, and snippets.

@ajamaica
Created June 7, 2012 18:49
Show Gist options
  • Save ajamaica/2890738 to your computer and use it in GitHub Desktop.
Save ajamaica/2890738 to your computer and use it in GitHub Desktop.
from django.db import models
import ParsePy
ParsePy.APPLICATION_ID = ""
ParsePy.MASTER_KEY = ""
class ParseObject(models.Model):
objectdId = models.CharField(max_length=100, null=True, blank = True)
class Meta:
abstract = True
def save(self, *args, **kwargs):
if not self.id :
obj = ParsePy.ParseObject(str(self.__class__()).replace(" object",""))
for attr in self.__dict__:
setattr(obj, attr , getattr(self, attr));
obj.save()
self.objectdId = obj.objectId()
else:
obj = ParsePy.ParseQuery(str(self.__class__()).replace(" object","")).get(self.objectdId)
for attr in self.__dict__:
if not attr in ['id',]:
setattr(obj, attr , getattr(self, attr));
obj.save()
self.objectdId = obj.objectId()
super(ParseObject, self).save(*args, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment