mirror of https://github.com/snachodog/mybuddy.git
child slugs: allow unicode
This results in %-encoded URLs, but modern browsers display the unicode chars (e.g. https://babybuddy.../children/мааян-паскин-чернявский).
This commit is contained in:
parent
f58571bf17
commit
29ef9f4f75
|
@ -5,7 +5,7 @@ from django.conf import settings
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.template.defaultfilters import slugify
|
from django.utils.text import slugify
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.text import format_lazy
|
from django.utils.text import format_lazy
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
@ -80,6 +80,7 @@ class Child(models.Model):
|
||||||
verbose_name=_('Birth date')
|
verbose_name=_('Birth date')
|
||||||
)
|
)
|
||||||
slug = models.SlugField(
|
slug = models.SlugField(
|
||||||
|
allow_unicode=True,
|
||||||
blank=False,
|
blank=False,
|
||||||
editable=False,
|
editable=False,
|
||||||
max_length=100,
|
max_length=100,
|
||||||
|
@ -107,7 +108,7 @@ class Child(models.Model):
|
||||||
return '{} {}'.format(self.first_name, self.last_name)
|
return '{} {}'.format(self.first_name, self.last_name)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
self.slug = slugify(self)
|
self.slug = slugify(self, allow_unicode=True)
|
||||||
super(Child, self).save(*args, **kwargs)
|
super(Child, self).save(*args, **kwargs)
|
||||||
cache.set(self.cache_key_count, Child.objects.count(), None)
|
cache.set(self.cache_key_count, Child.objects.count(), None)
|
||||||
|
|
||||||
|
|
|
@ -8,14 +8,14 @@ app_name = 'core'
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('children/', views.ChildList.as_view(), name='child-list'),
|
path('children/', views.ChildList.as_view(), name='child-list'),
|
||||||
path('children/add/', views.ChildAdd.as_view(), name='child-add'),
|
path('children/add/', views.ChildAdd.as_view(), name='child-add'),
|
||||||
path('children/<slug:slug>/', views.ChildDetail.as_view(), name='child'),
|
path('children/<str:slug>/', views.ChildDetail.as_view(), name='child'),
|
||||||
path(
|
path(
|
||||||
'children/<slug:slug>/edit/',
|
'children/<str:slug>/edit/',
|
||||||
views.ChildUpdate.as_view(),
|
views.ChildUpdate.as_view(),
|
||||||
name='child-update'
|
name='child-update'
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
'children/<slug:slug>/delete/',
|
'children/<str:slug>/delete/',
|
||||||
views.ChildDelete.as_view(),
|
views.ChildDelete.as_view(),
|
||||||
name='child-delete'
|
name='child-delete'
|
||||||
),
|
),
|
||||||
|
|
|
@ -8,7 +8,7 @@ app_name = 'dashboard'
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('dashboard/', views.Dashboard.as_view(), name='dashboard'),
|
path('dashboard/', views.Dashboard.as_view(), name='dashboard'),
|
||||||
path(
|
path(
|
||||||
'children/<slug:slug>/dashboard/',
|
'children/<str:slug>/dashboard/',
|
||||||
views.ChildDashboard.as_view(),
|
views.ChildDashboard.as_view(),
|
||||||
name='dashboard-child'
|
name='dashboard-child'
|
||||||
),
|
),
|
||||||
|
|
|
@ -7,42 +7,42 @@ app_name = 'reports'
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path(
|
path(
|
||||||
'children/<slug:slug>/reports/changes/amounts/',
|
'children/<str:slug>/reports/changes/amounts/',
|
||||||
views.DiaperChangeAmounts.as_view(),
|
views.DiaperChangeAmounts.as_view(),
|
||||||
name='report-diaperchange-amounts-child'
|
name='report-diaperchange-amounts-child'
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
'children/<slug:slug>/reports/changes/lifetimes/',
|
'children/<str:slug>/reports/changes/lifetimes/',
|
||||||
views.DiaperChangeLifetimesChildReport.as_view(),
|
views.DiaperChangeLifetimesChildReport.as_view(),
|
||||||
name='report-diaperchange-lifetimes-child'
|
name='report-diaperchange-lifetimes-child'
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
'children/<slug:slug>/reports/changes/types/',
|
'children/<str:slug>/reports/changes/types/',
|
||||||
views.DiaperChangeTypesChildReport.as_view(),
|
views.DiaperChangeTypesChildReport.as_view(),
|
||||||
name='report-diaperchange-types-child'
|
name='report-diaperchange-types-child'
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
'children/<slug:slug>/reports/feeding/amounts/',
|
'children/<str:slug>/reports/feeding/amounts/',
|
||||||
views.FeedingAmountsChildReport.as_view(),
|
views.FeedingAmountsChildReport.as_view(),
|
||||||
name='report-feeding-amounts-child'
|
name='report-feeding-amounts-child'
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
'children/<slug:slug>/reports/feeding/duration/',
|
'children/<str:slug>/reports/feeding/duration/',
|
||||||
views.FeedingDurationChildReport.as_view(),
|
views.FeedingDurationChildReport.as_view(),
|
||||||
name='report-feeding-duration-child'
|
name='report-feeding-duration-child'
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
'children/<slug:slug>/reports/sleep/pattern/',
|
'children/<str:slug>/reports/sleep/pattern/',
|
||||||
views.SleepPatternChildReport.as_view(),
|
views.SleepPatternChildReport.as_view(),
|
||||||
name='report-sleep-pattern-child'
|
name='report-sleep-pattern-child'
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
'children/<slug:slug>/reports/sleep/totals/',
|
'children/<str:slug>/reports/sleep/totals/',
|
||||||
views.SleepTotalsChildReport.as_view(),
|
views.SleepTotalsChildReport.as_view(),
|
||||||
name='report-sleep-totals-child'
|
name='report-sleep-totals-child'
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
'children/<slug:slug>/reports/weight/weight/',
|
'children/<str:slug>/reports/weight/weight/',
|
||||||
views.WeightWeightChildReport.as_view(),
|
views.WeightWeightChildReport.as_view(),
|
||||||
name='report-weight-weight-child'
|
name='report-weight-weight-child'
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in New Issue