class Token(Document): uuid = StringField(max_length=50, required=True) created_at = DateTimeField(auto_now_on_insert=True) expiry_at = DateTimeField() site = URLField(required=True) def __str__(self): return self.uuid
class BaseDoc(Document): SOURCE_LIST = ['京东', '天猫', '苏宁', '一号店', '飞牛'] STATUS_LIST = ['ERROR', 'ACTIVE', 'DELETED'] status = StringField(db_field='status', max_length=20, required=True, default="ACTIVE") create_at = DateTimeField(auto_now_on_insert=True) update_at = DateTimeField( auto_now_on_insert=True, auto_now_on_update=True)
class User(Document): username = StringField(required=True, max_length=245) token = StringField(required=True, max_length=245) session_id = StringField(max_length=245) created_at = DateTimeField(auto_now_on_insert=True) last_activity = DateTimeField() is_staff = BooleanField(default=False) is_active = BooleanField(default=True) def __str__(self): return self.username
class Message(Document): token = ReferenceField(Token) user = ReferenceField(User) body = StringField() datetime = DateTimeField(auto_now_on_insert=True) def __str__(self): return self.body
class Test(BaseModel): s_date = DateTimeField(default=datetime.datetime.now()) e_date = DateTimeField(default=datetime.datetime.now())
class XaceBlogContainer(motorengine.Document): #oid = StringField(default="") elements = ReferenceField(reference_document_type=XaceBlog) #{} #type is element changelog= ReferenceField(reference_document_type=XaceChangeList)#{} #type is change log comments= ReferenceField(reference_document_type=XaceCommentsList)#{} #type is change log notes= ReferenceField(reference_document_type=XaceSideNotesList)#{} #type is change log refers=ReferenceField(reference_document_type=XaceSideReferList) # reference for editor mode createTime =DateTimeField() lastTouched =DateTimeField(auto_now_on_update=True) #elementsType = StringField(default="") title = StringField(default="default Element") createby = StringField(default="") readCount = IntField(default=0) keywords= ListField(StringField()) allowUser = ListField(StringField()) @gen.coroutine def coCreate(self,user,alias=None,): self.elements =xl = yield XaceBlog().objects.create(authors=[user]) lgl = XaceChangeList() curch = XaceChange(operator=user,lastChange=datetime.datetime.utcnow(),tag=("create by "+user),refernceXele=xl._id) lgl.default.append(curch) self.changelog = yield lgl.save() self.createby = user self.comments = cmt = yield XaceCommentsList.objects.create() self.refers =yield XaceSideReferList.objects.create() self.notes =yield XaceSideNotesList.objects.create() self.createTime = datetime.datetime.now() created = yield self.save() print created raise gen.Return(created) #new document have been filled out side @gen.coroutine def coSave(self,user,element,changetag,alias=None): yield self.load_references(fields=["changelog"]) userlist =set() userlist.add(user) for change in self.changelog.default: userlist.add(change.operator) print userlist element.authors = list(userlist) print userlist self.elements = xl = yield element.save() curch = XaceChange(operator=user,lastChange=datetime.datetime.utcnow(),tag=changetag,refernceXele=xl._id) self.changelog.default.append(curch) self.title = element.title yield self.changelog.save() ret = yield self.save() raise gen.Return(ret)
class XaceComments(motorengine.Document): lastChange =DateTimeField() operator =StringField() tag = StringField(default="default")
class XaceChange(motorengine.Document): lastChange =DateTimeField() operator =StringField() tag = StringField(default="default") refernceXele =ObjectIdField()