Commit 30743c91 authored by Jose Luis Bautista's avatar Jose Luis Bautista

Added Key Model Functionality

parent 451aa8aa
from django import forms from django import forms
from django.forms import ModelForm
from .models import key_model
class home(forms.Form): class home(forms.Form):
name = forms.CharField(label='Name: ', max_length = 25) name = forms.CharField(label='Name: ', max_length = 25)
...@@ -6,9 +8,11 @@ class home(forms.Form): ...@@ -6,9 +8,11 @@ class home(forms.Form):
class profile(forms.Form): class profile(forms.Form):
name = forms.CharField(label='', max_length = 25) name = forms.CharField(label='', max_length = 25)
class key(forms.Form): class key(forms.ModelForm):
name = forms.CharField(label='', max_length = 25) class Meta:
model = key_model
fields = ['keyName','keyDesc']
class this_week(forms.Form): class this_week(forms.Form):
name = forms.CharField(label='', max_length = 25) name = forms.CharField(label='', max_length = 25)
......
# Generated by Django 3.1.8 on 2021-04-06 09:56
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='key_model',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('keyName', models.CharField(max_length=25)),
('keyDesc', models.CharField(max_length=25)),
],
),
]
...@@ -16,7 +16,7 @@ Including another URLconf ...@@ -16,7 +16,7 @@ Including another URLconf
from django.contrib import admin from django.contrib import admin
from django.urls import path from django.urls import path
from .views import page_home, page_profile, page_key, page_today, page_this_week, page_today, KeyListView from .views import page_home, page_profile, page_key, page_today, page_this_week, page_today, KeyListView, new_key
urlpatterns = [ urlpatterns = [
#path('admin/', admin.site.urls), #path('admin/', admin.site.urls),
...@@ -26,5 +26,6 @@ urlpatterns = [ ...@@ -26,5 +26,6 @@ urlpatterns = [
path('key/', KeyListView.as_view(), name = 'key'), path('key/', KeyListView.as_view(), name = 'key'),
path('this_week/', page_this_week, name = 'this_week'), path('this_week/', page_this_week, name = 'this_week'),
path('today/', page_today, name = 'today'), path('today/', page_today, name = 'today'),
path('new_key/', new_key, name = 'new_key'),
] ]
from django.shortcuts import render from django.shortcuts import render, reverse, redirect
from django.http import HttpResponse from django.http import HttpResponse
from django.views.generic import View, ListView from django.views.generic import View, ListView
from datetime import datetime from datetime import datetime
...@@ -33,6 +33,15 @@ def page_key(request): ...@@ -33,6 +33,15 @@ def page_key(request):
def page_this_week(request): def page_this_week(request):
return render(request, 'this_week.html') return render(request, 'this_week.html')
def new_key(request):
form = key()
if request.method == 'POST':
form = key(request.POST)
if form.is_valid():
form.save()
return redirect('key')
return render(request,'new_key.html', {'form' : form})
def page_today(request): def page_today(request):
myDate = datetime.now() myDate = datetime.now()
......
...@@ -5,12 +5,25 @@ ...@@ -5,12 +5,25 @@
{% block header %}Key{% endblock %} {% block header %}Key{% endblock %}
{% block body %} {% block body %}
<br>
<h3> Key : Description </h3>
<h3> • Tasks: Things you have to do </h3> <h3> • Tasks: Things you have to do </h3>
<h3> - Notes: Things you don't want to forget</h3> <h3> - Notes: Things you don't want to forget</h3>
<h3> O Events: Noteworthy moments in time </h3> <h3> O Events: Noteworthy moments in time </h3>
<h4> • Task incomplete </h4>
<h4> x Task complete </h4> <ul>
{% for x in object_list %}
{{x.keyName}} : {{x.keyDesc}}
<br>
{% endfor %}
</ul>
<button align = "center" href = "{% url 'new_key' %}">Add New Key</button>
{% endblock %} {% endblock %}
\ No newline at end of file
<h1> Type here new key: </h1>
<form action = '' method = "POST">
{% csrf_token %}
{{ form }}
<input type="submit" name="submit" id = "submit" value = "Click to add">
</form>
\ No newline at end of file
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
{% block body %} {% block body %}
<h1> {{date}} </h1> <h1> 3.24.WED </h1>
<h3> • Pabili ni baby </h3> <h3> • Pabili ni baby </h3>
<h3> • NBI Clearance </h3> <h3> • NBI Clearance </h3>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment