chore: add new field and basic typing

This commit is contained in:
Mike 2021-10-20 07:05:23 -07:00
parent 24a03bf6fc
commit 98c6be3ba5
2 changed files with 50 additions and 16 deletions

View file

@ -1,9 +1,10 @@
# Generated by Django 3.2.4 on 2021-06-17 22:20
from django.db import migrations, models
from test_project.models import MAX_CHARFIELD_LEN
class Migration(migrations.Migration):
"""Initial migration for test_project."""
initial = True
@ -22,8 +23,11 @@ class Migration(migrations.Migration):
verbose_name='ID',
),
),
('name', models.CharField(max_length=12)),
('name', models.CharField(max_length=MAX_CHARFIELD_LEN)),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='ExampleModel',
@ -37,8 +41,11 @@ class Migration(migrations.Migration):
verbose_name='ID',
),
),
('name', models.CharField(max_length=12)),
('name', models.CharField(max_length=MAX_CHARFIELD_LEN)),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='RegisterTestModel',
@ -52,8 +59,11 @@ class Migration(migrations.Migration):
verbose_name='ID',
),
),
('name', models.CharField(max_length=12)),
('name', models.CharField(max_length=MAX_CHARFIELD_LEN)),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='Patient',
@ -67,17 +77,21 @@ class Migration(migrations.Migration):
verbose_name='ID',
),
),
('name', models.CharField(max_length=12)),
('name', models.CharField(max_length=MAX_CHARFIELD_LEN)),
('email', models.EmailField(blank=True, max_length=MAX_CHARFIELD_LEN)),
(
'example',
models.ForeignKey(
blank=True,
null=True,
on_delete=models.deletion.PROTECT,
to='examplemodel',
to='test_project.examplemodel',
),
),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='M2MModel',
@ -91,9 +105,12 @@ class Migration(migrations.Migration):
verbose_name='ID',
),
),
('name', models.CharField(max_length=12)),
('models', models.ManyToManyField(to='ExampleModel')),
('name', models.CharField(max_length=MAX_CHARFIELD_LEN)),
('models', models.ManyToManyField(to='test_project.ExampleModel')),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='Encounter',
@ -112,9 +129,12 @@ class Migration(migrations.Migration):
'patient',
models.ForeignKey(
on_delete=models.deletion.PROTECT,
to='patient',
to='test_project.patient',
),
),
],
options={
'abstract': False,
},
),
]

View file

@ -1,8 +1,13 @@
from typing import Final, final
from django.db import models
from eav.decorators import register_eav
from eav.models import EAVModelMeta
#: Constants
MAX_CHARFIELD_LEN: Final = 254
class TestBase(models.Model):
"""Base class for test models."""
@ -14,10 +19,15 @@ class TestBase(models.Model):
abstract = True
@final
class Patient(TestBase):
name = models.CharField(max_length=12)
name = models.CharField(max_length=MAX_CHARFIELD_LEN)
email = models.EmailField(max_length=MAX_CHARFIELD_LEN, blank=True)
example = models.ForeignKey(
'ExampleModel', null=True, blank=True, on_delete=models.PROTECT
'ExampleModel',
null=True,
blank=True,
on_delete=models.PROTECT,
)
def __str__(self):
@ -39,31 +49,35 @@ class Encounter(TestBase):
@register_eav()
@final
class ExampleModel(TestBase):
name = models.CharField(max_length=12)
name = models.CharField(max_length=MAX_CHARFIELD_LEN)
def __unicode__(self):
return self.name
@register_eav()
@final
class M2MModel(TestBase):
name = models.CharField(max_length=12)
name = models.CharField(max_length=MAX_CHARFIELD_LEN)
models = models.ManyToManyField(ExampleModel)
def __unicode__(self):
return self.name
@final
class ExampleMetaclassModel(TestBase, metaclass=EAVModelMeta):
name = models.CharField(max_length=12)
name = models.CharField(max_length=MAX_CHARFIELD_LEN)
def __str__(self):
return self.name
@final
class RegisterTestModel(TestBase, metaclass=EAVModelMeta):
name = models.CharField(max_length=12)
name = models.CharField(max_length=MAX_CHARFIELD_LEN)
def __str__(self):
return self.name