Add api app with ApiToken model
This commit is contained in:
parent
53bc690435
commit
32adb64dc0
0
shynet/api/__init__.py
Normal file
0
shynet/api/__init__.py
Normal file
3
shynet/api/admin.py
Normal file
3
shynet/api/admin.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
6
shynet/api/apps.py
Normal file
6
shynet/api/apps.py
Normal file
@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ApiConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'api'
|
30
shynet/api/migrations/0001_initial.py
Normal file
30
shynet/api/migrations/0001_initial.py
Normal file
@ -0,0 +1,30 @@
|
||||
# Generated by Django 3.2.5 on 2021-10-11 09:31
|
||||
|
||||
import api.models
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='ApiToken',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=64)),
|
||||
('value', models.TextField(default=api.models._default_token_value, unique=True)),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='api_tokens', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'ordering': ['name', 'value'],
|
||||
},
|
||||
),
|
||||
]
|
0
shynet/api/migrations/__init__.py
Normal file
0
shynet/api/migrations/__init__.py
Normal file
19
shynet/api/models.py
Normal file
19
shynet/api/models.py
Normal file
@ -0,0 +1,19 @@
|
||||
from django.db import models
|
||||
from core.models import User
|
||||
from secrets import token_urlsafe
|
||||
|
||||
|
||||
def _default_token_value():
|
||||
return token_urlsafe(32)
|
||||
|
||||
|
||||
class ApiToken(models.Model):
|
||||
name = models.CharField(max_length=64)
|
||||
value = models.TextField(default=_default_token_value, unique=True)
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="api_tokens")
|
||||
|
||||
class Meta:
|
||||
ordering = ["name", "value"]
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
3
shynet/api/tests.py
Normal file
3
shynet/api/tests.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
3
shynet/api/views.py
Normal file
3
shynet/api/views.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
@ -59,6 +59,7 @@ INSTALLED_APPS = [
|
||||
"core",
|
||||
"dashboard.apps.DashboardConfig",
|
||||
"analytics",
|
||||
"api",
|
||||
"allauth",
|
||||
"allauth.account",
|
||||
"allauth.socialaccount",
|
||||
|
Loading…
Reference in New Issue
Block a user