Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session 14 to Session 15 #15

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
13f302e
Update for session 8 content
wsot Aug 11, 2022
db72024
Content for session 9. Tidy up URLs and Views.
wsot Aug 18, 2022
813a809
Session 10 - add search
wsot Aug 18, 2022
509bb13
Session 10 - multi-field search
wsot Aug 18, 2022
80a5ffb
Session 10 - Add search to generic view
wsot Aug 18, 2022
91af556
Session 10 - text in search box
wsot Aug 18, 2022
a3cb85e
Session 10 - you searched for text
wsot Aug 18, 2022
4a80446
Session 10 - you searched for text in CBV
wsot Aug 18, 2022
67997f4
Session 10 - Django form
wsot Aug 18, 2022
81a9b9d
Show message if no results
wsot Aug 22, 2022
a6e9a78
Handle search from any page
wsot Aug 22, 2022
3e0dd80
Add get_object_or_404
wsot Aug 22, 2022
528f096
Add basic form
wsot Aug 22, 2022
c77a180
Add list of choices with country code and country name
wsot Aug 25, 2022
fd2cbcd
Add list of choices with just country name
wsot Aug 25, 2022
8f29b25
Use 'TextChoices' for countries
wsot Aug 25, 2022
9fdd85c
Change form to use UL
wsot Aug 25, 2022
a0d9e2a
Add ChoicesField
wsot Aug 25, 2022
f0363b9
Switch to using ModelForm
wsot Aug 25, 2022
cc42faf
Use instance feature of ModelForm
wsot Aug 25, 2022
541e9da
Add PersonUpdateView
wsot Aug 29, 2022
9baad9d
Add basic check_my_auth view
wsot Aug 29, 2022
893fbf4
Login
wsot Aug 29, 2022
793cdb5
Add permission check
wsot Aug 31, 2022
9790b0b
Edit only own profile
wsot Aug 31, 2022
427150e
Handle multiple users for profile
wsot Aug 31, 2022
37a1e42
Initial advanced search
wsot Sep 5, 2022
c1d173f
Template list include
wsot Sep 5, 2022
fdd9d6a
Template include custom text
wsot Sep 5, 2022
8103367
Template include custom text 2
wsot Sep 5, 2022
1df30a5
Choices but no blank option
wsot Sep 5, 2022
a768e06
Choices with blank option
wsot Sep 5, 2022
e84a1f4
Add sorting
wsot Sep 5, 2022
fc31b67
Only show results when search performed
wsot Sep 5, 2022
8b3aa56
add migration
wsot Sep 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Content for session 9. Tidy up URLs and Views.
  • Loading branch information
wsot committed Sep 19, 2022
commit db72024d5464859f565aa0882fb34eac1b48286b
14 changes: 14 additions & 0 deletions src/community_db/templates/community_db/person_detail_in_base.html
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 %}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
This is my list of folks
<ul>
{% for person in object_list %}
<li>{{ person.first_name }} {{ person.last_name }}
from {{ person.country }}</li>
<li>
<a href="{% url 'fbv-person-detail' person.id %}">
{{ person.first_name }} {{ person.last_name }}
</a> from {{ person.country }}
</li>
{% endfor %}
</ul>
{% endblock %}
40 changes: 14 additions & 26 deletions src/community_db/views.py
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"
15 changes: 12 additions & 3 deletions src/pacificconnect/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@

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()),
path("fbv/people/", views.list_persons_with_template, name="fbv-person-list"),
path(
"fbv/people/<int:pk>/",
views.detail_person_with_template,
name="fbv-person-detail",
),
path("cbv/people/", views.PersonListView.as_view(), name="cbv-person-list"),
path(
"cbv/people/<int:pk>/",
views.PersonDetailView.as_view(),
name="cbv-person-detail",
),
]