class Bike(model.RedisModel): database = test_database namespace = 'database-contrib-tests' name = fields.StringField(indexable=True) wheels = fields.StringField(default=2) passengers = fields.StringField(default=1, cacheable=False)
class Boat(TestRedisModel): """ Use also InstanceHashField. """ name = fields.StringField(unique=True) power = fields.InstanceHashField(indexable=True, default="sail") launched = fields.StringField(indexable=True) length = fields.StringField()
class Boat(TestRedisModel): """ Use also HashableField. """ cacheable = False name = fields.StringField(unique=True) power = fields.HashableField(indexable=True, default="sail") launched = fields.StringField(indexable=True) length = fields.StringField()
class MyJob(Job): """ A job that will use Person's PK as identifier, and will store results of callback in a new field """ result = fields.StringField() # to store the result of the task queue_model = MyQueue queue_name = QUEUE_NAME start = fields.InstanceHashField(indexable=True) def get_object(self): """ Return the object concerned by the current job's identifier """ return Person.get(self.identifier.hget()) def run(self, queue): """ Create the fullname, and store a a message serving as result in the job """ # add some random time to simulate a long job time.sleep(random.random()) # compute the fullname obj = self.get_object() obj.fullname.hset('%s %s' % tuple(obj.hmget('firstname', 'lastname'))) # this will the "result" of the job result = 'Created fullname for Person %s: %s' % (obj.pk.get(), obj.fullname.hget()) # save the result of the callback in the job itself self.result.set(result) # return the result for future use in the worker return result
class ThreadableModel(model.RedisModel): database = db1 foo = fields.StringField()
class Bike(TestRedisModel): name = fields.StringField(indexable=True) wheels = fields.StringField(default=2) passengers = fields.StringField(default=1)
class Bike2(TestRedisModel): name = fields.StringField() namespace = 'sub-tests'
class Bike5(six.with_metaclass(TestMetaClass, TestRedisModel)): name = fields.StringField() namespace = 'sub-tests2'
class Person(TestRedisModel): namespace = 'collection' id = fields.AutoPKField() name = fields.StringField(indexable=True)
class M(RelatedModel): namespace = 'transfert-db-relations' abstract = True foo = fields.StringField()
class MultiIndexTestModel(TestRedisModel): name = fields.StringField(indexable=True, indexes=[index_class], unique=True)
class Train(TestRedisModel): namespace = "test_stringfield_keys_are_deleted" name = fields.StringField(unique=True) kind = fields.StringField(indexable=True) wagons = fields.StringField(default=10)
class ExtendedError(Error): namespace = 'test-errortests' foo = fields.StringField() bar = fields.StringField()
class ExtendedJob(Job): namespace = 'test-jobstest' foo = fields.StringField() bar = fields.StringField()
class Ferry(TestRedisModel): name = fields.StringField(unique=True)
class Vegetable(TestRedisModel): name = fields.StringField(indexable=True) color = fields.StringField() pip = fields.StringField(indexable=True)
class MotorBike(Bike): power = fields.StringField()
class Person(TestRedisModel): name = fields.PKField() age = fields.StringField(indexable=True) prefered_group = FKStringField('Group') following = M2MSetField('self', related_name='followers')
class ExtendedQueue(Queue): namespace = 'test-queuestest' foo = fields.StringField() bar = fields.StringField()
class Bike6( future.utils.with_metaclass(TestMetaClass, TestRedisModel)): name = fields.StringField() namespace = 'sub-tests2'
class Train(TestRedisModel): namespace = "test_model_delete" name = fields.InstanceHashField(unique=True) kind = fields.StringField(indexable=True) wagons = fields.InstanceHashField(default=10)
class AutoPkModel(TestRedisModel): name = fields.StringField(indexable=True)
class Group(TestRedisModel): name = fields.PKField() status = fields.StringField(indexable=True) owner = FKInstanceHashField(Person, related_name='owned_groups') parent = FKStringField('self', related_name='children') members = M2MSetField(Person, related_name='membership')
class NotAutoPkModel(TestRedisModel): pk = fields.PKField() name = fields.StringField(indexable=True)
class WithoutDB(model.RedisModel): name = fields.StringField()
class Bike(TestRedisModel): name = fields.StringField()
class MyEmail(TestRedisModel): subject = fields.StringField(indexable=True) headers = fields.HashField(indexable=True)
class Bike3(TestRedisModel): __metaclass__ = TestMetaClass name = fields.StringField() namespace = 'sub-tests2'