Skip to content

Commit 8420bea

Browse files
committed
fix error when captcha picture is lost & add unique to the captcha key field
1 parent 1ea49a9 commit 8420bea

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 3.1rc1 on 2020-07-31 02:26
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('captcha', '0003_auto_20200729_2208'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='captchastore',
15+
name='key',
16+
field=models.IntegerField(unique=True),
17+
),
18+
]

captcha/models.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
# Create your models here.
88
class CaptchaStore(models.Model):
9-
key = models.IntegerField()
9+
key = models.IntegerField(unique=True)
1010
answer = models.CharField(max_length=10)
1111
added_time = models.DateTimeField(auto_now=True)
1212

@@ -17,6 +17,9 @@ def clean_expire(self):
1717
expired_data = self.objects.filter(added_time__gte=tools.settimelater(timezone.now()))
1818
for edata in expired_data:
1919
path = os.path.join(settings.BASE_DIR, "uploads", "captcha", "{name}.png".format(name=edata.key))
20-
os.remove(path)
20+
try:
21+
os.remove(path)
22+
except FileNotFoundError:
23+
pass
2124

2225
edata.delete()

0 commit comments

Comments
 (0)