QRTR-3 reworked initial setup

This commit is contained in:
DJ Gillespie 2019-11-11 20:00:16 -07:00
parent d0dc71ad19
commit a8acfd05ba
33 changed files with 131 additions and 11 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,10 +1,11 @@
from django.contrib.auth.models import User, Group
from django.contrib.auth.models import Group
from django.contrib.auth import get_user_model
from rest_framework import serializers
class UserSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = User
model = get_user_model()
fields = ['url', 'username', 'email', 'groups']

Binary file not shown.

View File

@ -38,8 +38,21 @@ INSTALLED_APPS = [
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken',
'rest_auth',
'django.contrib.sites',
'allauth',
'allauth.account',
'rest_auth.registration',
'api',
'user',
]
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
SITE_ID = 1
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
@ -81,6 +94,7 @@ DATABASES = {
}
}
AUTH_USER_MODEL = 'user.User'
# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators

View File

@ -16,17 +16,22 @@ Including another URLconf
from django.contrib import admin
from django.urls import include, path
from rest_framework import routers
from api import views
from user.views import UserViewSet, GroupViewSet
router = routers.DefaultRouter()
router.register(r'users', views.UserViewSet)
router.register(r'groups', views.GroupViewSet)
router.register(r'users', UserViewSet)
router.register(r'groups', GroupViewSet)
# Wire up our API using automatic URL routing.
# Additionally, we include login URLs for the browsable API.
apipatterns = [
path('', include(router.urls)),
path('auth/', include('rest_framework.urls', namespace='rest_framework'), name='auth'),
path('auth/registration/', include('rest_auth.registration.urls'), name='register'),
]
urlpatterns = [
path('admin/', admin.site.urls),
path('', include(router.urls)),
path('api-auth/', include('rest_framework.urls', namespace='rest_framework'))
path('api/v1/', include(apipatterns), name='api'),
]

Binary file not shown.

3
qrtr_account/admin.py Normal file
View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

5
qrtr_account/apps.py Normal file
View File

@ -0,0 +1,5 @@
from django.apps import AppConfig
class QrtrAccountConfig(AppConfig):
name = 'qrtr_account'

21
qrtr_account/models.py Normal file
View File

@ -0,0 +1,21 @@
from django.db import models
from user.models import User
class Account(models.Model):
owner = models.ForeignKey(User, on_delete=models.CASCADE)
admin_users = models.ManyToManyField(User, related_name="admins")
view_users = models.ManyToManyField(User, related_name="viewer")
name = models.CharField(max_length=250)
class InstitutionAccount(models.Model):
qrtr_account = models.ForeignKey(Account, on_delete=models.CASCADE)
name = models.CharField(max_length=250)
id = models.CharField(max_length=150)
balance = models.DecimalField()
ac_type = models.CharField()
ac_subtype = models.CharField()
class Transaction(models.Model):
pass

3
qrtr_account/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

3
qrtr_account/views.py Normal file
View File

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

0
user/__init__.py Normal file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

3
user/admin.py Normal file
View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

5
user/apps.py Normal file
View File

@ -0,0 +1,5 @@
from django.apps import AppConfig
class UserConfig(AppConfig):
name = 'user'

View File

@ -0,0 +1,45 @@
# Generated by Django 2.2.6 on 2019-11-12 01:26
import django.contrib.auth.models
import django.contrib.auth.validators
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
initial = True
dependencies = [
('auth', '0011_update_proxy_permissions'),
]
operations = [
migrations.CreateModel(
name='User',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
('first_name', models.CharField(blank=True, max_length=30, verbose_name='first name')),
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('name', models.CharField(blank=True, max_length=255)),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')),
],
options={
'verbose_name': 'user',
'verbose_name_plural': 'users',
'abstract': False,
},
managers=[
('objects', django.contrib.auth.models.UserManager()),
],
),
]

View File

Binary file not shown.

8
user/models.py Normal file
View File

@ -0,0 +1,8 @@
from django.contrib.auth.models import AbstractUser
from django.db import models
class User(AbstractUser):
name = models.CharField(blank=True, max_length=255)
def __str__(self):
return self.email

3
user/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

View File

@ -1,4 +1,5 @@
from django.contrib.auth.models import User, Group
from django.contrib.auth.models import Group
from django.contrib.auth import get_user_model
from rest_framework import viewsets
from api.serializers import UserSerializer, GroupSerializer
@ -7,7 +8,7 @@ class UserViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows users to be viewed or edited.
"""
queryset = User.objects.all().order_by('-date_joined')
queryset = get_user_model().objects.all().order_by('-date_joined')
serializer_class = UserSerializer