Compare commits
2 Commits
c4086b9f46
...
a8e24fad63
| Author | SHA1 | Date | |
|---|---|---|---|
| a8e24fad63 | |||
| 97c0e0db0d |
@@ -1,5 +1,6 @@
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
import secrets
|
||||
|
||||
# Status choices for tasks
|
||||
STATUS_CHOICES = [
|
||||
@@ -21,6 +22,13 @@ class Client(models.Model):
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
# Generate a unique token if this is a new client
|
||||
if not self.pk and not self.token:
|
||||
# Use secrets module to generate a secure random token
|
||||
self.token = secrets.token_urlsafe(64) # 64 bytes -> ~86 characters
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
class Meta:
|
||||
verbose_name = '客户端'
|
||||
verbose_name_plural = '客户端'
|
||||
|
||||
Reference in New Issue
Block a user