def handle(self, **options):
last_month = datetime.today() - timedelta(days=30)
clients = Client.objects.filter(lastConnection__gte=last_month).values_list('uid','lastConnection')
#print list(clients)
last_year = datetime.today() - timedelta(days = 365)
uid_list = Client.objects.filter()
last_year_clients = Client.objects.filter(lastConnection__gte=last_year,uid__starstwith="%0000000000000000000000000009897").values_list('uid','lastConnection')
print list(last_year_clients)
这是处理程序,模块如下:
class Client(models.Model):
uid = models.CharField(max_length=128)
key = models.CharField(max_length=128)
img = models.TextField()
version = models.CharField(max_length=20)
lastConnection = models.DateTimeField()
role = models.CharField(max_length=128,default="")
def __str__(self):
return "%s"%self.uid
我要提取自一年以来没有登录的用户,并且ID以“ u'%000000000000000000000000000'”开头 基本上,我想排除这种类型的ID,并列出自一年以来未登录的用户。
任何帮助将不胜感激。
谢谢。
答案 0 :(得分:0)
last_year = datetime.today() - timedelta(days = 365)
uid_list = Client.objects.filter()
last_year_clients = Client.objects.filter(lastConnection__lte=last_year).exclude(uid__startswith="%00000").values_list('uid','lastConnection')
with open("last_year.txt","wb") as fp:
for s in last_year_clients:
fp.write(str(s)+"\n")