newmediamonitoring1/polls/models.py

29 lines
875 B
Python
Raw Normal View History

2020-08-20 07:38:42 +00:00
from django.db import models
2020-08-20 10:34:14 +00:00
import uuid
import datetime
2020-08-20 07:38:42 +00:00
2020-08-20 10:34:14 +00:00
VERIFY_CODE_TYPE_CHOICES = (
(0, 'register'),
(1, 'password_recover'),
)
class VerifyCode(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
code = models.CharField('code', max_length=8, null=False)
phone = models.CharField('phone', max_length=11, null=False)
timeouted = models.DateTimeField('timeouted', null=False)
category = models.IntegerField('category', choices=VERIFY_CODE_TYPE_CHOICES, default=0)
added = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
class Meta:
ordering = ["-added"]
def is_in_progress(self):
now = datetime.datetime.now()
2020-08-24 14:35:47 +00:00
return now <= self.timeouted
2020-08-20 10:34:14 +00:00
def __str__(self):
return self.phone + ':' + self.code