From 13f302ea9b63b0e02a7ab86ff3eedbebbd0004b2 Mon Sep 17 00:00:00 2001 From: Simeon J Morgan Date: Thu, 11 Aug 2022 15:43:02 +1000 Subject: [PATCH] Update for session 8 content --- src/community_db/admin.py | 12 +++++- src/community_db/models.py | 2 +- src/community_db/templates/base.html | 9 +++++ .../templates/community_db/person_list.html | 13 ++++++ .../community_db/person_list_in_base.html | 11 +++++ src/community_db/views.py | 40 ++++++++++++++++++- src/pacificconnect/urls.py | 5 +++ 7 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 src/community_db/templates/base.html create mode 100644 src/community_db/templates/community_db/person_list.html create mode 100644 src/community_db/templates/community_db/person_list_in_base.html diff --git a/src/community_db/admin.py b/src/community_db/admin.py index 8c38f3f..e7a3b1f 100644 --- a/src/community_db/admin.py +++ b/src/community_db/admin.py @@ -1,3 +1,13 @@ from django.contrib import admin -# Register your models here. +from .models import Person + + +class PersonAdmin(admin.ModelAdmin): + list_display = ( + "first_name", + "last_name", + ) + + +admin.site.register(Person, PersonAdmin) diff --git a/src/community_db/models.py b/src/community_db/models.py index f0853ab..9106665 100644 --- a/src/community_db/models.py +++ b/src/community_db/models.py @@ -3,6 +3,6 @@ class Person(models.Model): first_name = models.CharField(max_length=100) - last_name = models.CharField(max_length=100, blank=True) + last_name = models.CharField(max_length=100) country = models.CharField(max_length=100, blank=True) mobile_number = models.CharField(max_length=20, blank=True) diff --git a/src/community_db/templates/base.html b/src/community_db/templates/base.html new file mode 100644 index 0000000..56ac5bc --- /dev/null +++ b/src/community_db/templates/base.html @@ -0,0 +1,9 @@ + + + +

Welcome to the Pacific Connect Community Database

+ On this site, you can find details of members of the Pacific Connect Community Database + {% block content %}{% endblock %} + + + \ No newline at end of file diff --git a/src/community_db/templates/community_db/person_list.html b/src/community_db/templates/community_db/person_list.html new file mode 100644 index 0000000..92c0a9a --- /dev/null +++ b/src/community_db/templates/community_db/person_list.html @@ -0,0 +1,13 @@ + + + + This is my list of folks + + + + \ No newline at end of file diff --git a/src/community_db/templates/community_db/person_list_in_base.html b/src/community_db/templates/community_db/person_list_in_base.html new file mode 100644 index 0000000..bca85c5 --- /dev/null +++ b/src/community_db/templates/community_db/person_list_in_base.html @@ -0,0 +1,11 @@ +{% extends "base.html" %} + +{% block content %} + This is my list of folks + +{% endblock %} \ No newline at end of file diff --git a/src/community_db/views.py b/src/community_db/views.py index 91ea44a..1b0d3dd 100644 --- a/src/community_db/views.py +++ b/src/community_db/views.py @@ -1,3 +1,41 @@ +from django.http import HttpResponse from django.shortcuts import render +from django.template import loader +from django.views.generic.list import ListView -# Create your views here. +from community_db.models import Person + + +def list_persons(request): + html = "This is my list of folks" + return HttpResponse(html) + + +# def list_persons_with_template(request): +# persons = Person.objects.all() +# template = loader.get_template("community_db/person_list.html") +# context = {"object_list": persons} +# return HttpResponse(template.render(context, request)) + + +def list_persons_with_template(request): + persons = Person.objects.all() + template = loader.get_template("community_db/person_list_in_base.html") + context = {"object_list": persons} + return HttpResponse(template.render(context, request)) + + +# def list_persons_with_template(request): +# persons = Person.objects.all() +# context = {"object_list": persons} +# return render(request, "community_db/person_list.html", context) + + +class PersonListView(ListView): + model = Person + template_name = "community_db/person_list_in_base.html" diff --git a/src/pacificconnect/urls.py b/src/pacificconnect/urls.py index 5a454ad..c06409c 100644 --- a/src/pacificconnect/urls.py +++ b/src/pacificconnect/urls.py @@ -16,6 +16,11 @@ from django.contrib import admin from django.urls import path +from community_db import views + urlpatterns = [ path("admin/", admin.site.urls), + path("myview", views.list_persons), + path("myview-with-template/", views.list_persons_with_template), + path("person-list/", views.PersonListView.as_view()), ]