标签:point poi 地址 max address ESS pad 创建 用户登录
保存用户的登录日志该怎么做?
创建 用户登录日志数据库表
在 MVC 中创建相应的模型
class LoginLog(models.Model): """登录日志""" # 日志ID logid = models.BigAutoField(primary_key=True) # 登录的用户 user = models.ForeignKey(to=User, on_delete=models.DO_NOTHING, db_column=‘userid‘) # 登录的IP地址 ipaddr = models.CharField(max_length=255) # 登录的日期 logdate = models.DateTimeField(auto_now_add=True) # 登录的设备编码 devcode = models.CharField(max_length=255, default=‘‘) class Meta: managed = False db_table = ‘tb_login_log‘
with atomic(): current_time = timezone.now() if not user.lastvisit or (current_time - user.lastvisit).days >= 1: user.point += 2 user.lastvisit = current_time user.save() loginlog = LoginLog() loginlog.user = user loginlog.logdate = current_time loginlog.ipaddr = get_ip_address(request) loginlog.save()
标签:point poi 地址 max address ESS pad 创建 用户登录
原文地址:https://www.cnblogs.com/z-y-l/p/13055663.html