parent
eb11156301
commit
b8c6793d19
@ -0,0 +1 @@
|
|||||||
|
.env
|
||||||
@ -1,3 +1,5 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
from .models import Contact
|
||||||
|
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
|
admin.site.register(Contact)
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
from django import forms
|
||||||
|
from .models import Contact
|
||||||
|
|
||||||
|
class ContactForm(forms.modelForm):
|
||||||
|
class Meta:
|
||||||
|
model = Contact
|
||||||
|
fields = ('name', 'age',)
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
body {
|
||||||
|
font-family: Arial, Helvetica, sans-serif;
|
||||||
|
}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
{% load static %}
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Contacts</title>
|
||||||
|
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Phonebook</h1>
|
||||||
|
<!-- where all other content will go when this template is extended to other files -->
|
||||||
|
{% block content %} {% endblock %}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
<!-- including the base.html as a boilerplate -->
|
||||||
|
{% extends 'contacts/base.html' %} {% block content %}
|
||||||
|
<!-- contact detail content -->
|
||||||
|
<h2>{{ contact.name }} <a href="">(edit)</a></h2>
|
||||||
|
<h4>Age: {{ contact.age }}</h4>
|
||||||
|
{% endblock %}
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
<!-- including the base.html as a boilerplate -->
|
||||||
|
{% extends 'contacts/base.html' %} {% block content %}
|
||||||
|
<!-- contact list content -->
|
||||||
|
<h2>Contacts <a href="">(+)</a></h2>
|
||||||
|
<ul>
|
||||||
|
{% for contact in contacts %}
|
||||||
|
<li>
|
||||||
|
<a href="{% url 'contact_detail' pk=contact.pk %}">{{ contact.name }}</a>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endblock %}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
from django.urls import path
|
||||||
|
from . import views
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path('', views.contact_list, name='contact_list'),
|
||||||
|
path('contacts/<int:pk>', views.contact_detail, name='contact_detail'),
|
||||||
|
]
|
||||||
@ -1,3 +1,15 @@
|
|||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
from .models import Contact
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
|
## index
|
||||||
|
def contact_list(request):
|
||||||
|
contacts = Contact.objects.all()
|
||||||
|
return render(request, 'contacts/contact_list.html', { 'contacts': contacts})
|
||||||
|
|
||||||
|
## show
|
||||||
|
def contact_detail(request, pk):
|
||||||
|
contact = Contact.objects.get(id=pk)
|
||||||
|
return render(request, 'contacts/contact_detail.html', {'contact': contact})
|
||||||
Loading…
Reference in new issue