class Network(MongoModel): network = fields.BinaryField() filename = fields.CharField() def save(self, cascade=None, full_clean=True, force_insert=False): self.network = pickle.dumps(self.network) return super(Network, self).save(cascade, full_clean, force_insert)
class Rules(MongoModel): user = fields.CharField(required=True) rules = fields.BinaryField(required=True) created_on = fields.DateTimeField(required=True) class Meta: write_concern = WriteConcern(j=True) connection_alias = 'recommend-ahp'
class Application(MongoModel): _id = fields.CharField(required=True, primary_key=True) app_id = fields.CharField(required=True, verbose_name='app_id', mongo_name='appId') app_hash = fields.CharField(required=True, verbose_name='app_hash', mongo_name='appHash') app_secure = fields.BinaryField(required=True, verbose_name='app_secure', mongo_name='appCrypt') app_manager = fields.EmbeddedDocumentField(AppManager, required=True, verbose_name='app_manager_info', mongo_name='appManager') created_date = fields.DateTimeField(verbose_name='app_created_date', mongo_name='createdDate', required=True) app_is_valid = fields.BooleanField(required=True, verbose_name='app_is_valid', mongo_name='isValid', default=True) valid_until = fields.DateTimeField(required=True, verbose_name='app_valid_until', mongo_name='validUntil') is_deleted = fields.BooleanField(verbose_name='app_is_deleted', mongo_name='isDeleted', default=False) deleted_date = fields.DateTimeField(verbose_name='user_deleted_date', mongo_name='deletedDate', default=None) class Meta: connection_alias = 'Application' collection_name = 'registeredApps' cascade = True write_concern = wc.WriteConcern(j=True) read_preference = ReadPreference.NEAREST read_concern = rc.ReadConcern(level='majority') indexes = [ IndexModel('appId', name='appIdIndex', unique=True, sparse=True), IndexModel('appHash', name='appHashIndex', unique=True, sparse=True), IndexModel('appCrypt', name='appCryptIndex', unique=True, sparse=True), IndexModel('createdDate', name='createdDateIndex', sparse=True), IndexModel('validUntil', name='validUntilIndex', sparse=True), IndexModel('appManager.email', name='managerEmailIndex', sparse=True, unique=True) ] ignore_unknown_fields = True
class User(MongoModel): _id = fields.BigIntegerField(required=True, primary_key=True) uid = fields.BigIntegerField(required=True, verbose_name='user_id', mongo_name='userId') first_name = fields.CharField(verbose_name='user_first_name', mongo_name='firstName', default=None) last_name = fields.CharField(verbose_name='user_first_name', mongo_name='lastName', default=None) username = fields.CharField(verbose_name='user_username', mongo_name='userUsername', default=None, validators=[validate_username]) profile_photo = fields.CharField(verbose_name='user_profile_photo', mongo_name='profilePhoto', default=None) profile_thumbnail = fields.CharField(verbose_name='user_profile_thumbnail', mongo_name='profileThumb', default=None) is_deleted = fields.BooleanField(verbose_name='user_is_deleted', mongo_name='isDeleted', default=False) join_date = fields.DateTimeField(verbose_name='user_join_date', mongo_name='joinedDate', required=True) deleted_date = fields.DateTimeField(verbose_name='user_deleted_date', mongo_name='deletedDate', default=None) user_secure = fields.BinaryField(required=True, verbose_name='user_secure', mongo_name='secure') class Meta: connection_alias = 'Users' collection_name = 'users' cascade = True write_concern = wc.WriteConcern(j=True) read_preference = ReadPreference.NEAREST read_concern = rc.ReadConcern(level='majority') indexes = [ IndexModel('userUsername', name='usernameIndex', unique=True, sparse=True), IndexModel('userId', name='userIdIndex', unique=True, sparse=True) ] ignore_unknown_fields = True
class Person(MongoModel): first_name = fields.CharField() middle_name = fields.CharField() surname = fields.CharField() birth_date = fields.DateTimeField() phone_no = fields.CharField() photo = fields.BinaryField() notes = fields.CharField() ss_rating = fields.FloatField(default=None, blank=True) hs_rating = fields.FloatField(default=None, blank=True) spec_rating = fields.FloatField(default=None, blank=True) auth_key = fields.CharField(blank=True) #rating = fields.FloatField(default=None, blank=True) # TODO нужно оставить либо поле rating, либо метод get_rating - смотреть по производиельности def get_rating(self): if (self.ss_rating == self.hs_rating == self.spec_rating == None): return None return ( (self.ss_rating or 50) + (self.hs_rating or 50) + (self.spec_rating or 50) * 2)\ / 4 class Meta: write_concern = WriteConcern(w=1) connection_alias = "reviewer" final = True indexes = [ IndexModel([("phone_no", pymongo.DESCENDING)], unique=True, partialFilterExpression={"phone_no": { "$exists": True }}), IndexModel("first_name"), IndexModel("middle_name"), IndexModel("surname") ]