mirror of https://github.com/snachodog/mybuddy.git
Make last name optional (#361)
This commit is contained in:
parent
8f6d0295f3
commit
89ed408acc
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 3.2.10 on 2021-12-29 20:30
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('core', '0016_alter_sleep_napping'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='child',
|
||||||
|
name='last_name',
|
||||||
|
field=models.CharField(blank=True, max_length=255, verbose_name='Last name'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -73,7 +73,11 @@ def validate_time(time, field_name):
|
||||||
class Child(models.Model):
|
class Child(models.Model):
|
||||||
model_name = 'child'
|
model_name = 'child'
|
||||||
first_name = models.CharField(max_length=255, verbose_name=_('First name'))
|
first_name = models.CharField(max_length=255, verbose_name=_('First name'))
|
||||||
last_name = models.CharField(max_length=255, verbose_name=_('Last name'))
|
last_name = models.CharField(
|
||||||
|
blank=True,
|
||||||
|
max_length=255,
|
||||||
|
verbose_name=_('Last name')
|
||||||
|
)
|
||||||
birth_date = models.DateField(
|
birth_date = models.DateField(
|
||||||
blank=False,
|
blank=False,
|
||||||
null=False,
|
null=False,
|
||||||
|
@ -105,7 +109,7 @@ class Child(models.Model):
|
||||||
verbose_name_plural = _('Children')
|
verbose_name_plural = _('Children')
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '{} {}'.format(self.first_name, self.last_name)
|
return self.name()
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
self.slug = slugify(self, allow_unicode=True)
|
self.slug = slugify(self, allow_unicode=True)
|
||||||
|
@ -117,9 +121,10 @@ class Child(models.Model):
|
||||||
cache.set(self.cache_key_count, Child.objects.count(), None)
|
cache.set(self.cache_key_count, Child.objects.count(), None)
|
||||||
|
|
||||||
def name(self, reverse=False):
|
def name(self, reverse=False):
|
||||||
|
if not self.last_name:
|
||||||
|
return self.first_name
|
||||||
if reverse:
|
if reverse:
|
||||||
return '{}, {}'.format(self.last_name, self.first_name)
|
return '{}, {}'.format(self.last_name, self.first_name)
|
||||||
|
|
||||||
return '{} {}'.format(self.first_name, self.last_name)
|
return '{} {}'.format(self.first_name, self.last_name)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
Loading…
Reference in New Issue