Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
53 lines (44 sloc) 1.9 KB
import datetime
from django.db import models
from django.contrib.contenttypes.models import ContentType
class SyncedObjectManager(models.Manager):
def for_model(self, obj):
Look up the sycned record for a given model.
Returns a QuerySet, not the original instance. That's so that you
can do either::
>>> SyncedObject.objects.for_model(obj).exists()
>>> SyncedObject.objects.for_model(obj).get()
<SyncedObject: ...>
Depending on what information you need.
return self.filter(
content_type = ContentType.objects.get_for_model(obj),
object_pk =,
def mark_synced(self, django_obj, storymarket_obj):
Mark ``django_obj`` as having been synced to ``storymarket_obj``.
Returns ``(SyncedObject, created)``, just like ``get_or_create()``.
defaults = dict(
storymarket_type = storymarket_obj.__class__.__name__.lower(),
storymarket_id =,
tags = storymarket_obj.tags,
org =,
category =,
pricing = ( if storymarket_obj.pricing_scheme else None),
rights = ( if storymarket_obj.rights_scheme else None),
last_updated =,
so, created = self.get_or_create(
content_type = ContentType.objects.get_for_model(django_obj),
object_pk =,
defaults = defaults,
if not created:
return so, created