当创建一个客户端的时候,自动创建一个API Token
This commit is contained in:
@@ -14,15 +14,15 @@ Including another URLconf
|
|||||||
1. Import the include() function: from django.urls import include, path
|
1. Import the include() function: from django.urls import include, path
|
||||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
"""
|
"""
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.conf.urls.static import static
|
from django.conf.urls.static import static
|
||||||
from tasks.views_frontend import index
|
from tasks.views_frontend import index
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('houtai/', admin.site.urls),
|
path('houtai/', admin.site.urls),
|
||||||
path('api/', include('tasks.urls')),
|
path('api/', include('tasks.urls')),
|
||||||
# Root URL points to home page
|
# Root URL points to home page
|
||||||
path('', index, name='index'),
|
path('', index, name='index'),
|
||||||
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||||
|
|||||||
@@ -53,4 +53,4 @@ class TaskResultAdmin(admin.ModelAdmin):
|
|||||||
'classes': ('collapse',)
|
'classes': ('collapse',)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
import secrets
|
||||||
|
|
||||||
# Status choices for tasks
|
# Status choices for tasks
|
||||||
STATUS_CHOICES = [
|
STATUS_CHOICES = [
|
||||||
@@ -20,6 +21,13 @@ class Client(models.Model):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
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:
|
class Meta:
|
||||||
verbose_name = '客户端'
|
verbose_name = '客户端'
|
||||||
|
|||||||
Reference in New Issue
Block a user