Add basic api for account requests, refs #2
This commit is contained in:
parent
c566b4a8bb
commit
f2c2b5493b
7 changed files with 65 additions and 0 deletions
25
userausfall/migrations/0002_accountrequest.py
Normal file
25
userausfall/migrations/0002_accountrequest.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
# Generated by Django 2.2.13 on 2021-04-12 08:56
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('userausfall', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='AccountRequest',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('created_time', models.DateTimeField(auto_now_add=True)),
|
||||||
|
('email', models.EmailField(max_length=254)),
|
||||||
|
('is_verified', models.BooleanField(default=False)),
|
||||||
|
('confidant_email', models.EmailField(blank=True, max_length=254)),
|
||||||
|
('is_trustable', models.BooleanField(default=False)),
|
||||||
|
('username', models.CharField(blank=True, max_length=100)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
|
@ -1,5 +1,18 @@
|
||||||
from django.contrib.auth.models import AbstractUser
|
from django.contrib.auth.models import AbstractUser
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
class User(AbstractUser):
|
class User(AbstractUser):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class AccountRequest(models.Model):
|
||||||
|
created_time = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
||||||
|
email = models.EmailField()
|
||||||
|
is_verified = models.BooleanField(default=False)
|
||||||
|
|
||||||
|
confidant_email = models.EmailField(blank=True)
|
||||||
|
is_trustable = models.BooleanField(default=False)
|
||||||
|
|
||||||
|
username = models.CharField(max_length=100, blank=True)
|
||||||
|
|
0
userausfall/rest_api/__init__.py
Normal file
0
userausfall/rest_api/__init__.py
Normal file
9
userausfall/rest_api/serializers.py
Normal file
9
userausfall/rest_api/serializers.py
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
from userausfall.models import AccountRequest
|
||||||
|
|
||||||
|
|
||||||
|
class AccountRequestSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = AccountRequest
|
||||||
|
fields = ('url', 'email', 'confidant_email', 'username', 'is_verified', 'is_trustable')
|
6
userausfall/rest_api/urls.py
Normal file
6
userausfall/rest_api/urls.py
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
from rest_framework import routers
|
||||||
|
|
||||||
|
from userausfall.rest_api.views import AccountRequestViewSet
|
||||||
|
|
||||||
|
router = routers.DefaultRouter(trailing_slash=False)
|
||||||
|
router.register(r'account_requests', AccountRequestViewSet)
|
9
userausfall/rest_api/views.py
Normal file
9
userausfall/rest_api/views.py
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
from rest_framework import viewsets
|
||||||
|
|
||||||
|
from userausfall.models import AccountRequest
|
||||||
|
from userausfall.rest_api.serializers import AccountRequestSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class AccountRequestViewSet(viewsets.ModelViewSet):
|
||||||
|
serializer_class = AccountRequestSerializer
|
||||||
|
queryset = AccountRequest.objects.all()
|
|
@ -1,6 +1,9 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
|
|
||||||
|
from userausfall.rest_api import urls as rest_api_urls
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
|
path('api/', include(rest_api_urls.router.urls))
|
||||||
]
|
]
|
||||||
|
|
Reference in a new issue