-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Content for session 9. Tidy up URLs and Views.
- Loading branch information
Showing
4 changed files
with
45 additions
and
31 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
src/community_db/templates/community_db/person_detail_in_base.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
<br> | ||
<a href="{% url 'fbv-person-list' %}">Back to list</a> | ||
<br> | ||
This is the detail of a person: | ||
<ul> | ||
<li>First Name: {{ object.first_name }}</li> | ||
<li>Last Name: {{ object.last_name }}</li> | ||
<li>Country: {{ object.country }}</li> | ||
<li>Phone number: {{ object.mobile_number }}</li> | ||
</ul> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,29 @@ | ||
from django.http import HttpResponse | ||
from django.shortcuts import render | ||
from django.template import loader | ||
from django.views.generic.list import ListView | ||
from django.views.generic import DetailView, ListView | ||
|
||
from community_db.models import Person | ||
from .models import Person | ||
|
||
|
||
def list_persons(request): | ||
html = "<html><body>This is my list of folks<ul>" | ||
|
||
for person in Person.objects.all(): | ||
html += f"<li>{person.first_name} {person.last_name} from {person.country}</li>" | ||
|
||
html += "</ul></body></html>" | ||
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)) | ||
# FUNCTION BASED VIEWS | ||
|
||
|
||
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)) | ||
return render(request, "community_db/person_list_in_base.html", context) | ||
|
||
|
||
# def list_persons_with_template(request): | ||
# persons = Person.objects.all() | ||
# context = {"object_list": persons} | ||
# return render(request, "community_db/person_list.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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters