From: David Kerkeslager Date: Fri, 26 Feb 2021 16:50:10 +0000 (-0500) Subject: Start adding views X-Git-Url: https://code.kerkeslager.com/?p=tickle;a=commitdiff_plain;h=3b208d248d5fd0baf79d84fef493cf69db638f9c Start adding views --- diff --git a/core/urls.py b/core/urls.py index f0559db..0d79c71 100644 --- a/core/urls.py +++ b/core/urls.py @@ -14,8 +14,9 @@ Including another URLconf 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.urls import path +from django.urls import include, path urlpatterns = [ path('admin/', admin.site.urls), + path('climbing/', include('tickle.urls')), ] diff --git a/tickle/models.py b/tickle/models.py index 3b2deb8..86cb752 100644 --- a/tickle/models.py +++ b/tickle/models.py @@ -29,12 +29,14 @@ BOULDER_DIFFICULTY_CHOICES = ( ('v16', 'v16'), ) +# TODO Provide a way of getting only Area objects which contain boulders/routes class Area(models.Model): parent = models.ForeignKey( 'self', blank=True, null=True, on_delete=models.CASCADE, + related_name='children', ) name = models.CharField(max_length=64) notes = models.TextField(blank=True) @@ -46,7 +48,11 @@ class Area(models.Model): return '{} > {}'.format(self.parent, self.name) class Boulder(models.Model): - area = models.ForeignKey('Area', on_delete=models.PROTECT) + area = models.ForeignKey( + 'Area', + on_delete=models.PROTECT, + related_name='boulders', + ) name = models.CharField(max_length=64) difficulty = models.CharField( choices=BOULDER_DIFFICULTY_CHOICES, @@ -128,7 +134,11 @@ PROTECTION_STYLE_CHOICES = ( ) class Route(models.Model): - area = models.ForeignKey('Area', on_delete=models.PROTECT) + area = models.ForeignKey( + 'Area', + on_delete=models.PROTECT, + related_name='routes' + ) name = models.CharField(max_length=64) protection_style = models.CharField(max_length=8, choices=PROTECTION_STYLE_CHOICES) mountainproject = models.URLField(blank=True) diff --git a/tickle/templates/tickle/area_detail.html b/tickle/templates/tickle/area_detail.html new file mode 100644 index 0000000..b951f76 --- /dev/null +++ b/tickle/templates/tickle/area_detail.html @@ -0,0 +1,32 @@ + + + +

{{ area.name }}

+ + {% if area.children.count > 0 %} + + {% endif %} + + {% if area.boulders.count > 0 %} + Boulders + + {% endif %} + + {% if area.routes.count > 0 %} + Routes + + {% endif %} + + diff --git a/tickle/templates/tickle/area_list.html b/tickle/templates/tickle/area_list.html new file mode 100644 index 0000000..3cdadae --- /dev/null +++ b/tickle/templates/tickle/area_list.html @@ -0,0 +1,11 @@ + + + +

All Areas

+ + + diff --git a/tickle/templates/tickle/area_list_item.html b/tickle/templates/tickle/area_list_item.html new file mode 100644 index 0000000..de6bfcc --- /dev/null +++ b/tickle/templates/tickle/area_list_item.html @@ -0,0 +1,30 @@ +
  • +
    + {{ area.name }} +
    + {% if area.children.count > 0 %} + + {% endif %} + + {% if area.boulders.count > 0 %} + Boulders + + {% endif %} + + {% if area.routes.count > 0 %} + Routes + + {% endif %} +
  • diff --git a/tickle/urls.py b/tickle/urls.py new file mode 100644 index 0000000..06c007e --- /dev/null +++ b/tickle/urls.py @@ -0,0 +1,19 @@ +from django.urls import path + +from . import views + +# TODO Move attempts and todos to sub-area under user URLs +# TODO Use something other than primary keys in URLs + +app_name = 'tickle' + +urlpatterns = ( + path('area', views.area_list, name='area-list'), + path('area/', views.area_detail, name='area-detail'), + path('attempt', views.attempt_list, name='attempt-list'), + path('boulder', views.boulder_list, name='boulder-list'), + path('boulder/', views.boulder_detail, name='boulder-detail'), + path('route', views.route_list, name='route-list'), + path('route/', views.route_detail, name='route-detail'), + path('todo', views.todo_list, name='todo-list'), +) diff --git a/tickle/views.py b/tickle/views.py index 91ea44a..858d48c 100644 --- a/tickle/views.py +++ b/tickle/views.py @@ -1,3 +1,35 @@ -from django.shortcuts import render +from django.views.generic import DetailView, ListView -# Create your views here. +from . import models + +class AreaDetailView(DetailView): + model = models.Area +area_detail = AreaDetailView.as_view() + +class AreaListView(ListView): + queryset = models.Area.objects.filter(parent=None) +area_list = AreaListView.as_view() + +class AttemptListView(ListView): + pass +attempt_list = AttemptListView.as_view() + +class BoulderDetailView(DetailView): + pass +boulder_detail = BoulderDetailView.as_view() + +class BoulderListView(ListView): + pass +boulder_list = BoulderListView.as_view() + +class RouteDetailView(DetailView): + pass +route_detail = RouteDetailView.as_view() + +class RouteListView(ListView): + pass +route_list = RouteListView.as_view() + +class TodoListView(ListView): + pass +todo_list = TodoListView.as_view()