Commit a21dddca authored by Jose Luis Bautista's avatar Jose Luis Bautista

Added Today Functionality

parent 166317a1
from django import forms
from django.forms import ModelForm
from .models import key_model, profile_model
from .models import *
class home(forms.Form):
name = forms.CharField(label='Name: ', max_length = 25)
......@@ -28,5 +28,7 @@ class key(forms.ModelForm):
class this_week(forms.Form):
name = forms.CharField(label='', max_length = 25)
class today(forms.Form):
name = forms.CharField(label='', max_length = 25)
\ No newline at end of file
class today(forms.ModelForm):
class Meta:
model = today_model
fields = ['keyModel', 'todayDesc']
\ No newline at end of file
# Generated by Django 3.1.8 on 2021-04-08 04:47
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('BauDB', '0004_auto_20210407_1546'),
]
operations = [
migrations.CreateModel(
name='today_model',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('todayDesc', models.CharField(max_length=100)),
('keyModel', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='BauDB.key_model')),
],
),
]
# Generated by Django 3.1.8 on 2021-04-08 06:40
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('BauDB', '0005_today_model'),
]
operations = [
migrations.AlterField(
model_name='today_model',
name='todayDesc',
field=models.CharField(max_length=25),
),
]
# Generated by Django 3.1.8 on 2021-04-08 07:06
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('BauDB', '0006_auto_20210408_1440'),
]
operations = [
migrations.DeleteModel(
name='today_model',
),
]
# Generated by Django 3.1.8 on 2021-04-08 07:11
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('BauDB', '0007_delete_today_model'),
]
operations = [
migrations.CreateModel(
name='today_model',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('todayDesc', models.CharField(max_length=25)),
('keyModel', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='BauDB.key_model')),
],
),
]
# Generated by Django 3.1.8 on 2021-04-08 07:14
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('BauDB', '0008_today_model'),
]
operations = [
migrations.AlterField(
model_name='key_model',
name='keyDesc',
field=models.CharField(max_length=100),
),
migrations.AlterField(
model_name='today_model',
name='todayDesc',
field=models.CharField(max_length=100),
),
]
from django.db import models
from django.shortcuts import render, reverse, redirect
# Create your models here.
class key_model(models.Model):
keyName = models.CharField(max_length = 25)
keyDesc = models.CharField(max_length = 25)
keyDesc = models.CharField(max_length = 100)
def __str__(self):
return self.keyName
class profile_model(models.Model):
profileName = models.CharField(max_length = 25)
profileBio = models.CharField(max_length = 25)
profileImage = models.ImageField(upload_to ='images/', null = True)
class today_model(models.Model):
keyModel = models.ForeignKey(key_model, on_delete = models.CASCADE)
todayDesc = models.CharField(max_length=100)
def today_edit(self):
return reverse('new_today_update', args = [str(self.id)])
def today_delete(self):
return reverse('today_delete', args = [str(self.id)])
# def deltwtask(self):
# return reverse('deletetwtask', args=[str(self.id)])
......@@ -28,10 +28,12 @@ urlpatterns = [
path('profile/', ProfileDetailView.as_view(), name = 'profile'),
path('key/', KeyListView.as_view(), name = 'key'),
path('this_week/', page_this_week, name = 'this_week'),
path('today/', page_today, name = 'today'),
path('today/', TodayListView.as_view(), name = 'today'),
path('new_key/', new_key, name = 'new_key'),
path('new_today/', new_today, name = 'new_today'),
path('new_name/',ProfileNameView.as_view(), name = 'new_name'),
path('new_bio/',ProfileBioView.as_view(), name = 'new_bio'),
path('new_image/',ProfileImageView.as_view(), name = 'new_image'),
path('new_today_update/<int:pk>/',TodayUpdateView.as_view(), name = 'new_today_update'),
path('today_delete/<int:pk>/',TodayDeleteView.as_view(), name = 'today_delete'),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
from django.shortcuts import render, reverse, redirect
from django.http import HttpResponse
from django.views.generic import View, ListView, DetailView, UpdateView
from django.views.generic import View, ListView, DetailView, UpdateView, DeleteView
from datetime import datetime
from .forms import home, key, this_week, today,profileFormName, profileFormBio, profileFormImage
from .models import key_model, profile_model
from .forms import *
#from .forms import home, key, this_week, today,profileFormName, profileFormBio, profileFormImage
from .models import *
name = None
form = None
......@@ -32,6 +33,15 @@ def page_key(request):
def page_this_week(request):
return render(request, 'this_week.html')
def new_today(request):
form = today()
if request.method == 'POST':
form = today(request.POST)
if form.is_valid():
form.save()
return redirect('today')
return render(request,'update.html', {'form' : form})
def new_key(request):
form = key()
if request.method == 'POST':
......@@ -41,17 +51,18 @@ def new_key(request):
return redirect('key')
return render(request,'update.html', {'form' : form})
def page_today(request):
myDate = datetime.now()
formattedDate = myDate.strftime("%m.%d.%A")
return render(request, 'today.html', {'date': formattedDate})
################
class KeyListView(ListView):
model = key_model
template_name = 'key.html'
################
class ProfileDetailView(DetailView):
model = profile_model
template_name = 'profile.html'
......@@ -59,7 +70,6 @@ class ProfileDetailView(DetailView):
def get_object(self):
return profile_model.objects.first()
class ProfileNameView(UpdateView):
model = profile_model
template_name = 'update.html'
......@@ -92,4 +102,23 @@ class ProfileImageView(UpdateView):
def get_success_url(self):
return reverse('profile')
################
class TodayListView(ListView):
model = today_model
template_name = 'today.html'
class TodayUpdateView(UpdateView):
model = today_model
template_name = 'update.html'
form_class = today
def get_success_url(self):
return reverse('today')
class TodayDeleteView(DeleteView):
model = today_model
template_name = 'delete.html'
form_class = today
def get_success_url(self):
return reverse('today')
\ No newline at end of file
......@@ -126,6 +126,6 @@ USE_TZ = True
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'BauJo/static')]
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
<form action = '' method = "POST" enctype="multipart/form-data">
{% csrf_token %}
{{ form }}
<input type="submit" name="submit" id = "submit" value = "Input">
</form>
<a href = "{% url 'today' %}"><button>Don't Input</button></a>
\ No newline at end of file
......@@ -7,12 +7,7 @@
{% block body %}
<br>
<h3> Key : Description </h3>
<h3> • Tasks: Things you have to do </h3>
<h3> - Notes: Things you don't want to forget</h3>
<h3> O Events: Noteworthy moments in time </h3>
<ul>
{% for x in object_list %}
{{x.keyName}} : {{x.keyDesc}}
......
......@@ -8,10 +8,15 @@
<h1> 3.24.WED </h1>
<h3> • Pabili ni baby </h3>
<h3> • NBI Clearance </h3>
<h3> - Pabili ni baby </h3>
<h3> - Mga sinampay, baka umulan </h3>
<h3> O ML league stream (8pm) </h3>
{% for x in object_list %}
{{x.keyModel.keyName}} : {{x.todayDesc}} |
<a href = "{{ x.today_edit }}"><button>Edit</button></a>
<a href = "{{ x.today_delete }}"><button>Delete</button></a>
<br>
{% endfor %}
<br>
<a href = "{% url 'new_today' %}"><button>Add Item</button></a>
{% endblock %}
\ No newline at end of file
......@@ -2,5 +2,5 @@
<form action = '' method = "POST" enctype="multipart/form-data">
{% csrf_token %}
{{ form }}
<input type="submit" name="submit" id = "submit" value = "Add">
<input type="submit" name="submit" id = "submit" value = "Input">
</form>
\ No newline at end of file
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