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_detail_in_base.html b/src/community_db/templates/community_db/person_detail_in_base.html new file mode 100644 index 0000000..31102ff --- /dev/null +++ b/src/community_db/templates/community_db/person_detail_in_base.html @@ -0,0 +1,14 @@ +{% extends "base.html" %} + +{% block content %} +
+ Back to list +
+ This is the detail of a person: + +{% 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..d9d4ede --- /dev/null +++ b/src/community_db/templates/community_db/person_list_in_base.html @@ -0,0 +1,14 @@ +{% 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..d6ea8e0 100644 --- a/src/community_db/views.py +++ b/src/community_db/views.py @@ -1,3 +1,29 @@ from django.shortcuts import render +from django.views.generic import DetailView, ListView -# Create your views here. +from .models import Person + +# FUNCTION BASED VIEWS + + +def list_persons_with_template(request): + persons = Person.objects.all() + context = {"object_list": persons} + return render(request, "community_db/person_list_in_base.html", context) + + +def detail_person_with_template(request, pk): + person = Person.objects.get(id=pk) + context = {"object": person} + return render(request, "community_db/person_detail_in_base.html", context) + + +# CLASS BASED VIEWS +class PersonListView(ListView): + model = Person + template_name = "community_db/person_list_in_base.html" + + +class PersonDetailView(DetailView): + model = Person + template_name = "community_db/person_detail_in_base.html" diff --git a/src/pacificconnect/urls.py b/src/pacificconnect/urls.py index 5a454ad..d602477 100644 --- a/src/pacificconnect/urls.py +++ b/src/pacificconnect/urls.py @@ -16,6 +16,20 @@ from django.contrib import admin from django.urls import path +from community_db import views + urlpatterns = [ path("admin/", admin.site.urls), + path("fbv/people/", views.list_persons_with_template, name="fbv-person-list"), + path( + "fbv/people//", + views.detail_person_with_template, + name="fbv-person-detail", + ), + path("cbv/people/", views.PersonListView.as_view(), name="cbv-person-list"), + path( + "cbv/people//", + views.PersonDetailView.as_view(), + name="cbv-person-detail", + ), ]