Handle dashboard redirect when there are no Child objects.

This commit is contained in:
Christopher Charbonneau Wells 2017-08-24 08:04:54 -04:00
parent 78ebc87265
commit 536283e3db
1 changed files with 5 additions and 1 deletions

View File

@ -13,7 +13,11 @@ from core.models import Child
class DashboardRedirect(LoginRequiredMixin, RedirectView):
# Show the overall dashboard or a child dashboard if one Child instance.
def get(self, request, *args, **kwargs):
if Child.objects.count() == 1:
children = Child.objects.count()
if children == 0:
# TODO: Create some sort of welcome page.
self.url = reverse('child-add')
elif children == 1:
child_instance = Child.objects.first()
self.url = reverse('dashboard-child', args={child_instance.slug})
else: