Commit 6ba6c7fd authored by nikkastra's avatar nikkastra

key done but no dialog box

parent d983635d
...@@ -17,3 +17,9 @@ class Picture(forms.ModelForm): ...@@ -17,3 +17,9 @@ class Picture(forms.ModelForm):
class Meta: class Meta:
model = Name model = Name
fields = ['image'] fields = ['image']
class Keys(forms.ModelForm):
class Meta:
model = Key
fields = ['key', 'description']
\ No newline at end of file
# Generated by Django 3.1.7 on 2021-04-09 12:02
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('bulletjournal', '0003_auto_20210408_0629'),
]
operations = [
migrations.CreateModel(
name='Key',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('key', models.CharField(max_length=50)),
('description', models.CharField(max_length=100)),
],
),
migrations.AlterField(
model_name='name',
name='name',
field=models.CharField(default='test', max_length=100, unique=True),
),
]
...@@ -18,6 +18,14 @@ class Name(models.Model): ...@@ -18,6 +18,14 @@ class Name(models.Model):
return self.units == 1 return self.units == 1
class Key(models.Model):
key = models.CharField(max_length=50)
description = models.CharField(max_length=100)
def __str__(self):
return '{} - {}'.format(self.key, self.description)
class Tasks(models.Model): class Tasks(models.Model):
name = models.ForeignKey(Name, on_delete=models.CASCADE) name = models.ForeignKey(Name, on_delete=models.CASCADE)
key = models.CharField(max_length=2) key = models.CharField(max_length=2)
......
...@@ -88,7 +88,22 @@ def profile(request): ...@@ -88,7 +88,22 @@ def profile(request):
def key(request): def key(request):
return render(request, 'key.html') key_dict = {}
if request.method == 'POST':
form = Keys(request.POST)
if form.is_valid():
new_key = Key(key=form.cleaned_data['key'], description=form.cleaned_data['description'])
new_key.save()
key_dict = {'form': form}
the_keys = [str(x) for x in Key.objects.all()]
key_dict['the_keys'] = the_keys
return render(request, 'key.html', key_dict)
else:
form = Keys()
key_dict = {'form':form}
the_keys = [str(x) for x in Key.objects.all()]
key_dict['the_keys'] = the_keys
return render(request, 'key.html', key_dict)
def thisweek(request): def thisweek(request):
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
{% if name %} {% if name %}
<p>Hello, {{name}}! Today is gonna be a great day!</p> <p>Hello, {{name}}! Today is gonna be a great day!</p>
{% else %} {% else %}
<form action="/home" method="post"> <form action="{% url 'home'%}" method="post">
{% csrf_token %} {% csrf_token %}
{{form}} {{form}}
<input type="Submit" value="Submit"> <input type="Submit" value="Submit">
......
...@@ -8,9 +8,20 @@ ...@@ -8,9 +8,20 @@
{% block content %} {% block content %}
<h1> Key </h1> <h1> Key </h1>
<p> ● Tasks: things you have to do </p> <ul>
<p> - Notes: things you don't want to forget </p> {% if the_keys %}
<p> ◦ Events: noteworth moments in time </p> {% for x in the_keys %}
<p> ● Task incomplete </p> <li>
<p> x Task complete </p> {{x}}
</li>
{% endfor %}
{% else %}
<p> No keys. </p>
{% endif %}
</ul>
<form action="{% url 'key'%}" method="post">
{% csrf_token %}
{{form}}
<input type="Submit" value="Add">
</form>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
<li> {{name}} </li> <li> {{name}} </li>
<li> <li>
{{nickname}} {{nickname}}
<form action="/profile" method="POST" id='nickname'> <form action="{% url 'profile' %}" method="POST" id='nickname'>
{% csrf_token %} {% csrf_token %}
{{ form2 }} {{ form2 }}
<input type='Submit' value='Edit' id='nickname'> <input type='Submit' value='Edit' id='nickname'>
......
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