def valid_add(cls, params): name = params.get('name', '') tel = params.get('tel', '') age = params.get('age', '') sex = params.get('sex', '1') add_user_vaild = True is_valid = True user = User() errors = {} user.name = params.get('name', '').strip() if name == '': errors['name'] = '用户名输入不能为空' is_valid = False else: try: User.objects.get(name=name) errors['name'] = '用户名已存在' is_valid = False except BaseException as e: pass user.age = params.get('age', '0').strip() if age == '': errors['name'] = '年龄不能为空' is_valid = False if not cls.isinteger(user.age): errors['age'] = '年龄格式不正确' is_valid = False else: user.age = int(user.age) user.tel = params.get('tel', '0').strip() user.sex = params.get('sex', '0').strip() salt,allpassword = encrypt_password(params.get('password', '22').strip()) # user.password = params.get('password', '22').strip() user.salt = salt user.password = allpassword user.create_time = timezone.now() return is_valid, user, errors
# encoding: utf-8 # -*- coding: utf-8 -*- # author = ‘LW’ from user.models import User from datetime import datetime for i in range(10): u = User() u.name = 'kk_{0}'.format(i) u.age = i + 1 u.create_time = datetime.now() u.save() # < User.objects.filter(age__lt=5) # <= User.objects.filter(age__lte=5) # > User.objects.filter(age__gt=5) # >= User.objects.filter(age__gte=5) # like %% User.objects.filter(name__contains='kk') # like %val User.objects.filter(name__startswith='kk') # like val% User.objects.filter(name__endswith='9') # and User.objects.filter(age__gt=5, name__endswith='9') # in