def create_or_update(self, instance, timestamp=None, url=None, tags="", source="INTERACTIVE", source_id="", **kwargs):
        # If the instance hasn't already been saved, save it first. This
        # requires disconnecting the post-save signal that might be sent to
        # this function (otherwise we could get an infinite loop).
        if instance._get_pk_val() is None:
            try:
                signals.post_save.disconnect(self.create_or_update, sender=type(instance))
            except Exception, err:
                reconnect = False
            else:
                reconnect = True
            instance.save()
            if reconnect:
                signals.post_save.connect(self.create_or_update, sender=type(instance))
        
        # Make sure the item "should" be registered.
        if not getattr(instance, "jellyrollable", True):
            return
        
        # Check to see if the timestamp is being updated, possibly pulling
        # the timestamp from the instance.
        if hasattr(instance, "timestamp"):
            timestamp = instance.timestamp
        if timestamp is None:
            update_timestamp = False
            timestamp = datetime.datetime.now()
        else:
            update_timestamp = True
                    
        # Ditto for tags.
        if not tags:
            for f in instance._meta.fields:
                if isinstance(f, TagField):
                    tags = getattr(instance, f.attname)
                    break

        if not url:
            if hasattr(instance,'url'):
                url = instance.url

        # Create the Item object.
        ctype = ContentType.objects.get_for_model(instance)
        item, created = self.get_or_create(
            content_type = ctype, 
            object_id = force_unicode(instance._get_pk_val()),
            defaults = dict(
                timestamp = timestamp,
                source = source,
                source_id = source_id,
                tags = tags,
                url = url,
            )
        )        
        item.tags = tags
        item.source = source
        item.source_id = source_id
        if update_timestamp:
            item.timestamp = timestamp
            
        # Save and return the item.
        item.save()
        return item
Create or update an Item from some instace.
dataset/ETHPy150Open jacobian-archive/jellyroll/src/jellyroll/managers.py/ItemManager.create_or_update