Add fields to capture user personal information

This commit is contained in:
Tanner Collin 2018-07-24 00:24:30 +00:00
parent fd49f7d90e
commit 290a444216
3 changed files with 188 additions and 4 deletions

View File

@ -0,0 +1,157 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.1 on 2018-07-24 00:16
from __future__ import unicode_literals
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0006_auto_20180622_0533'),
]
operations = [
migrations.AddField(
model_name='client',
name='alt_address1',
field=models.CharField(default='-', max_length=100),
preserve_default=False,
),
migrations.AddField(
model_name='client',
name='alt_address2',
field=models.CharField(blank=True, max_length=100),
),
migrations.AddField(
model_name='client',
name='alt_city',
field=models.CharField(default='-', max_length=32),
preserve_default=False,
),
migrations.AddField(
model_name='client',
name='alt_name',
field=models.CharField(default='-', max_length=32),
preserve_default=False,
),
migrations.AddField(
model_name='client',
name='alt_phone_number',
field=models.CharField(default='-', 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}$')]),
preserve_default=False,
),
migrations.AddField(
model_name='client',
name='alt_province',
field=models.CharField(default='-', max_length=32),
preserve_default=False,
),
migrations.AddField(
model_name='manage',
name='relation',
field=models.CharField(blank=True, max_length=32),
),
migrations.AddField(
model_name='provider',
name='cert_date1',
field=models.DateField(blank=True, default='2018-01-01'),
preserve_default=False,
),
migrations.AddField(
model_name='provider',
name='cert_date2',
field=models.DateField(blank=True, default='2018-01-01'),
preserve_default=False,
),
migrations.AddField(
model_name='provider',
name='cert_date3',
field=models.DateField(blank=True, default='2018-01-01'),
preserve_default=False,
),
migrations.AddField(
model_name='provider',
name='cert_institution1',
field=models.CharField(blank=True, max_length=32),
),
migrations.AddField(
model_name='provider',
name='cert_institution2',
field=models.CharField(blank=True, max_length=32),
),
migrations.AddField(
model_name='provider',
name='cert_institution3',
field=models.CharField(blank=True, max_length=32),
),
migrations.AddField(
model_name='provider',
name='cert_title1',
field=models.CharField(blank=True, max_length=32),
),
migrations.AddField(
model_name='provider',
name='cert_title2',
field=models.CharField(blank=True, max_length=32),
),
migrations.AddField(
model_name='provider',
name='cert_title3',
field=models.CharField(blank=True, max_length=32),
),
migrations.AddField(
model_name='provider',
name='crim_record_check_date',
field=models.DateField(blank=True, default='2018-01-01'),
preserve_default=False,
),
migrations.AddField(
model_name='provider',
name='emerg_contact_name',
field=models.CharField(default='-', max_length=32),
preserve_default=False,
),
migrations.AddField(
model_name='provider',
name='emerg_contact_number',
field=models.CharField(default='-', 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}$')]),
preserve_default=False,
),
migrations.AddField(
model_name='userinfo',
name='address1',
field=models.CharField(default='-', max_length=100),
preserve_default=False,
),
migrations.AddField(
model_name='userinfo',
name='address2',
field=models.CharField(blank=True, max_length=100),
),
migrations.AddField(
model_name='userinfo',
name='city',
field=models.CharField(default='-', max_length=32),
preserve_default=False,
),
migrations.AddField(
model_name='userinfo',
name='dob',
field=models.DateField(default='2018-01-01'),
preserve_default=False,
),
migrations.AddField(
model_name='userinfo',
name='postal_code',
field=models.CharField(default='-', max_length=7, validators=[django.core.validators.RegexValidator(message="Phone number must be entered in the format: 'A1B 2C3'.", regex='^[a-zA-Z][0-9][a-zA-Z] [0-9][a-zA-Z][0-9]$')]),
preserve_default=False,
),
migrations.AddField(
model_name='userinfo',
name='province',
field=models.CharField(default='-', max_length=32),
preserve_default=False,
),
]

View File

@ -3,10 +3,18 @@ from django.contrib.auth.models import User
from django.db import models
from django.core.validators import RegexValidator
phone_regex = RegexValidator(regex=r'^\+?1?\d{9,15}$', message="Phone number must be entered in the format: '+999999999'. Up to 15 digits allowed.")
# Create your models here.
class UserInfo(models.Model):
user = models.OneToOneField(User)
phone_regex = RegexValidator(regex=r'^\+?1?\d{9,15}$', message="Phone number must be entered in the format: '+999999999'. Up to 15 digits allowed.")
dob = models.DateField()
address1 = models.CharField(max_length=100)
address2 = models.CharField(max_length=100, blank=True)
city = models.CharField(max_length=32)
province = models.CharField(max_length=32)
postal_code_regex = RegexValidator(regex=r'^[a-zA-Z][0-9][a-zA-Z] [0-9][a-zA-Z][0-9]$', message="Phone number must be entered in the format: 'A1B 2C3'.")
postal_code = models.CharField(validators=[postal_code_regex], max_length=7)
phone_number = models.CharField(validators=[phone_regex], max_length=16)
def __str__(self):
@ -15,6 +23,12 @@ class UserInfo(models.Model):
class Client(models.Model):
user = models.OneToOneField(User)
business_number = models.CharField(max_length=16)
alt_name = models.CharField(max_length=32)
alt_address1 = models.CharField(max_length=100)
alt_address2 = models.CharField(max_length=100, blank=True)
alt_city = models.CharField(max_length=32)
alt_province = models.CharField(max_length=32)
alt_phone_number = models.CharField(validators=[phone_regex], max_length=16)
def __str__(self):
return self.user.first_name + ' ' + self.user.last_name
@ -22,6 +36,18 @@ class Client(models.Model):
class Provider(models.Model):
user = models.OneToOneField(User)
sin = models.CharField(max_length=16)
cert_title1 = models.CharField(max_length=32, blank=True)
cert_date1 = models.DateField(blank=True)
cert_institution1 = models.CharField(max_length=32, blank=True)
cert_title2 = models.CharField(max_length=32, blank=True)
cert_date2 = models.DateField(blank=True)
cert_institution2 = models.CharField(max_length=32, blank=True)
cert_title3 = models.CharField(max_length=32, blank=True)
cert_date3 = models.DateField(blank=True)
cert_institution3 = models.CharField(max_length=32, blank=True)
emerg_contact_name = models.CharField(max_length=32)
emerg_contact_number = models.CharField(validators=[phone_regex], max_length=16)
crim_record_check_date = models.DateField(blank=True)
def __str__(self):
return self.user.first_name + ' ' + self.user.last_name
@ -41,6 +67,7 @@ class Manage(models.Model):
client = models.ForeignKey(Client, related_name='employees')
provider = models.ForeignKey(Provider, related_name='employers')
note = models.CharField(max_length=500, blank=True)
relation = models.CharField(max_length=32, blank=True)
approved = models.NullBooleanField(blank=True)
deleted = models.BooleanField(default=False)

View File

@ -8,7 +8,7 @@ from caremyway.api.models import UserInfo, Client, Provider, WorkType, Manage, P
class UserInfoSerializer(serializers.ModelSerializer):
class Meta:
model = UserInfo
fields = ('phone_number',)
fields = ('dob', 'address1', 'address2', 'city', 'province', 'postal_code', 'phone_number')
def create(self, validated_data):
validated_data['user'] = self.context['request'].user
@ -116,7 +116,7 @@ class ClientSerializer(serializers.ModelSerializer):
class Meta:
model = Client
fields = ('business_number', 'work_types', 'employees')
fields = ('business_number', 'alt_name', 'alt_address1', 'alt_address2', 'alt_city', 'alt_province', 'alt_phone_number', 'work_types', 'employees')
def create(self, validated_data):
user = self.context['request'].user
@ -156,7 +156,7 @@ class ProviderSerializer(serializers.ModelSerializer):
class Meta:
model = Provider
fields = ('sin', 'employers')
fields = ('sin', 'cert_title1', 'cert_date1', 'cert_institution1', 'cert_title2', 'cert_date2', 'cert_institution2', 'cert_title3', 'cert_date3', 'cert_institution3', 'emerg_contact_name', 'emerg_contact_number', 'crim_record_check_date', 'employers')
def create(self, validated_data):
user = self.context['request'].user