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')),
]
('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)
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,
)
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)
--- /dev/null
+<html>
+ <head></head>
+ <body>
+ <h1>{{ area.name }}</h1>
+
+ {% if area.children.count > 0 %}
+ <ul>
+ {% for child in area.children.all %}
+ {% include 'tickle/area_list_item.html' with area=child %}
+ {% endfor %}
+ </ul>
+ {% endif %}
+
+ {% if area.boulders.count > 0 %}
+ Boulders
+ <ul>
+ {% for boulder in area.boulders.all %}
+ <li>{{ boulder.name }}</li>
+ {% endfor %}
+ </ul>
+ {% endif %}
+
+ {% if area.routes.count > 0 %}
+ Routes
+ <ul>
+ {% for route in area.routes.all %}
+ <li>{{ route.name }}</li>
+ {% endfor %}
+ </ul>
+ {% endif %}
+ </body>
+</html>
--- /dev/null
+<html>
+ <head></head>
+ <body>
+ <h1>All Areas</h1>
+ <ul>
+ {% for area in area_list %}
+ {% include 'tickle/area_list_item.html' %}
+ {% endfor %}
+ </ul>
+ </body>
+</html>
--- /dev/null
+<li>
+ <header>
+ <a href='{% url "tickle:area-detail" pk=area.pk %}'>{{ area.name }}</a>
+ </header>
+ {% if area.children.count > 0 %}
+ <ul>
+ {% for child in area.children.all %}
+ {% include 'tickle/area_list_item.html' with area=child %}
+ {% endfor %}
+ </ul>
+ {% endif %}
+
+ {% if area.boulders.count > 0 %}
+ Boulders
+ <ul>
+ {% for boulder in area.boulders.all %}
+ <li>{{ boulder.name }}</li>
+ {% endfor %}
+ </ul>
+ {% endif %}
+
+ {% if area.routes.count > 0 %}
+ Routes
+ <ul>
+ {% for route in area.routes.all %}
+ <li>{{ route.name }}</li>
+ {% endfor %}
+ </ul>
+ {% endif %}
+</li>
--- /dev/null
+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/<int:pk>', views.area_detail, name='area-detail'),
+ path('attempt', views.attempt_list, name='attempt-list'),
+ path('boulder', views.boulder_list, name='boulder-list'),
+ path('boulder/<int:pk>', views.boulder_detail, name='boulder-detail'),
+ path('route', views.route_list, name='route-list'),
+ path('route/<int:pk>', views.route_detail, name='route-detail'),
+ path('todo', views.todo_list, name='todo-list'),
+)
-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()