Create UserInfo, Client, and Provider models to extend User
This commit is contained in:
parent
f173618477
commit
3774f2ceb1
28
caremyway/api/migrations/0001_initial.py
Normal file
28
caremyway/api/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.1 on 2017-05-27 02:53
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
import django.core.validators
|
||||||
|
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='UserInfo',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('phone_number', models.CharField(blank=True, max_length=16, validators=[django.core.validators.RegexValidator(message="Phone number must be entered in the format: '+999999999'. Up to 15 digits allowed.", regex='^\\+?1?\\d{9,15}$')])),
|
||||||
|
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
22
caremyway/api/migrations/0002_auto_20170527_0338.py
Normal file
22
caremyway/api/migrations/0002_auto_20170527_0338.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.1 on 2017-05-27 03:38
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('api', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='userinfo',
|
||||||
|
name='user',
|
||||||
|
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='user_info', to=settings.AUTH_USER_MODEL),
|
||||||
|
),
|
||||||
|
]
|
22
caremyway/api/migrations/0003_auto_20170527_0439.py
Normal file
22
caremyway/api/migrations/0003_auto_20170527_0439.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.1 on 2017-05-27 04:39
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('api', '0002_auto_20170527_0338'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='userinfo',
|
||||||
|
name='user',
|
||||||
|
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
|
||||||
|
),
|
||||||
|
]
|
34
caremyway/api/migrations/0004_client_provider.py
Normal file
34
caremyway/api/migrations/0004_client_provider.py
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.1 on 2017-05-27 07:30
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
('api', '0003_auto_20170527_0439'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Client',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('business_number', models.CharField(blank=True, max_length=16)),
|
||||||
|
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Provider',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('sin', models.CharField(blank=True, max_length=16)),
|
||||||
|
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
|
@ -1,3 +1,18 @@
|
||||||
|
from django.contrib.auth.models import User
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.core.validators import RegexValidator
|
||||||
|
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
|
class UserInfo(models.Model):
|
||||||
|
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
||||||
|
phone_regex = RegexValidator(regex=r'^\+?1?\d{9,15}$', message="Phone number must be entered in the format: '+999999999'. Up to 15 digits allowed.")
|
||||||
|
phone_number = models.CharField(validators=[phone_regex], max_length=16, blank=True)
|
||||||
|
|
||||||
|
class Client(models.Model):
|
||||||
|
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
||||||
|
business_number = models.CharField(max_length=16, blank=True)
|
||||||
|
|
||||||
|
class Provider(models.Model):
|
||||||
|
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
||||||
|
sin = models.CharField(max_length=16, blank=True)
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,23 @@
|
||||||
from django.contrib.auth.models import User, Group
|
from django.contrib.auth.models import User, Group
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
from caremyway.api.models import UserInfo, Client, Provider
|
||||||
|
|
||||||
class UserSerializer(serializers.HyperlinkedModelSerializer):
|
class UserSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = User
|
model = User
|
||||||
fields = ('url', 'username', 'email', 'groups')
|
fields = ('url', 'username', 'first_name', 'last_name', 'email')
|
||||||
|
|
||||||
|
class UserInfoSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
class GroupSerializer(serializers.HyperlinkedModelSerializer):
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Group
|
model = UserInfo
|
||||||
fields = ('url', 'name')
|
fields = ('url', 'user', 'phone_number')
|
||||||
|
|
||||||
|
class ClientSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Client
|
||||||
|
fields = ('url', 'user', 'business_number')
|
||||||
|
|
||||||
|
class ProviderSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Provider
|
||||||
|
fields = ('url', 'user', 'sin')
|
||||||
|
|
|
@ -2,21 +2,22 @@ from django.shortcuts import render
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
from django.contrib.auth.models import User, Group
|
from django.contrib.auth.models import User, Group
|
||||||
|
from caremyway.api.models import UserInfo, Client, Provider
|
||||||
from rest_framework import viewsets
|
from rest_framework import viewsets
|
||||||
from caremyway.api.serializers import UserSerializer, GroupSerializer
|
from caremyway.api.serializers import UserSerializer, UserInfoSerializer, ClientSerializer, ProviderSerializer
|
||||||
|
|
||||||
|
|
||||||
class UserViewSet(viewsets.ModelViewSet):
|
class UserViewSet(viewsets.ModelViewSet):
|
||||||
"""
|
|
||||||
API endpoint that allows users to be viewed or edited.
|
|
||||||
"""
|
|
||||||
queryset = User.objects.all().order_by('-date_joined')
|
queryset = User.objects.all().order_by('-date_joined')
|
||||||
serializer_class = UserSerializer
|
serializer_class = UserSerializer
|
||||||
|
|
||||||
|
class UserInfoViewSet(viewsets.ModelViewSet):
|
||||||
|
queryset = UserInfo.objects.all().order_by('-id')
|
||||||
|
serializer_class = UserInfoSerializer
|
||||||
|
|
||||||
class GroupViewSet(viewsets.ModelViewSet):
|
class ClientViewSet(viewsets.ModelViewSet):
|
||||||
"""
|
queryset = Client.objects.all().order_by('-id')
|
||||||
API endpoint that allows groups to be viewed or edited.
|
serializer_class = ClientSerializer
|
||||||
"""
|
|
||||||
queryset = Group.objects.all()
|
class ProviderViewSet(viewsets.ModelViewSet):
|
||||||
serializer_class = GroupSerializer
|
queryset = Provider.objects.all().order_by('-id')
|
||||||
|
serializer_class = ProviderSerializer
|
||||||
|
|
|
@ -38,6 +38,7 @@ INSTALLED_APPS = [
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'rest_framework',
|
'rest_framework',
|
||||||
|
'caremyway.api',
|
||||||
]
|
]
|
||||||
|
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
|
|
|
@ -19,7 +19,9 @@ from caremyway.api import views
|
||||||
|
|
||||||
router = routers.DefaultRouter()
|
router = routers.DefaultRouter()
|
||||||
router.register(r'users', views.UserViewSet)
|
router.register(r'users', views.UserViewSet)
|
||||||
router.register(r'groups', views.GroupViewSet)
|
router.register(r'userinfos', views.UserInfoViewSet)
|
||||||
|
router.register(r'clients', views.ClientViewSet)
|
||||||
|
router.register(r'providers', views.ProviderViewSet)
|
||||||
|
|
||||||
# Wire up our API using automatic URL routing.
|
# Wire up our API using automatic URL routing.
|
||||||
# Additionally, we include login URLs for the browsable API.
|
# Additionally, we include login URLs for the browsable API.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user