def test_function(): def base_func(value=0, *args, **kwargs): result = value + sum(args) if 'addition' in kwargs: result += kwargs['addition'] return result function_field = fields.function(base_func) assert next(function_field) == 0 function_field = fields.function(base_func, 1) assert next(function_field) == 1 function_field = fields.function(base_func, 1, 2) assert next(function_field) == 3 function_field = fields.function(base_func, 1, 2, addition=3) assert next(function_field) == 6
class UserAnonym(register_models.AnonymBase): email = fields.string('test_email_{seq}@preply.com', seq_callback=datetime.datetime.now) username = fields.string('test_username_{seq}@preply.com', seq_callback=datetime.datetime.now) first_name = fields.string('first name {seq}') last_name = fields.string('last name {seq}') password = fields.password('password') is_staff = fields.function(lambda: False) class Meta: pass
class UserAnonym(AnonymBase): email = fields.string('test_email_{seq}@preply.com', seq_callback=datetime.datetime.now) username = fields.string('test_username_{seq}@preply.com', seq_callback=datetime.datetime.now) first_name = fields.string('first name {seq}') last_name = fields.string('last name {seq}') password = fields.password('password') is_staff = fields.function(lambda: False) class Meta: exclude_fields = ['is_active', 'is_superuser', 'last_login', 'date_joined']
class QuestionAnonym(AnonymBase): question_text = fields.string("John Doe {seq}") pub_date = fields.function(datetime.datetime.now)