Skip to content

Commit 997cc42

Browse files
Matthew HolmesMatthew Holmes
authored andcommitted
ading model forms notes
1 parent dc30212 commit 997cc42

File tree

20 files changed

+453
-0
lines changed

20 files changed

+453
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
3+
import os
4+
import sys
5+
6+
7+
def main():
8+
"""Run administrative tasks."""
9+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'todo_proj.settings')
10+
try:
11+
from django.core.management import execute_from_command_line
12+
except ImportError as exc:
13+
raise ImportError(
14+
"Couldn't import Django. Are you sure it's installed and "
15+
"available on your PYTHONPATH environment variable? Did you "
16+
"forget to activate a virtual environment?"
17+
) from exc
18+
execute_from_command_line(sys.argv)
19+
20+
21+
if __name__ == '__main__':
22+
main()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
body {
2+
background-color: aqua;
3+
}
4+
.all_tasks {
5+
width: 400px;
6+
7+
}
8+
.user_controls {
9+
/* display: flex;
10+
flex-direction: column; */
11+
text-align: end;
12+
}
13+
.tasks {
14+
display: flex;
15+
flex-direction: column;
16+
17+
border: 1px solid black;
18+
margin: 5px;
19+
}
20+
.item {
21+
text-decoration: underline;
22+
}
23+
.done {
24+
display: flex;
25+
flex-direction: column;
26+
border: 1px solid black;
27+
margin: 5px;
28+
29+
}
30+

Code/matthew/django/lectures/08_model_forms/todo_app/__init__.py

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from django.contrib import admin
2+
# * imports all from models
3+
from . models import *
4+
5+
# Register your models here.
6+
7+
admin.site.register(Task)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class TodoAppConfig(AppConfig):
5+
default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'todo_app'
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from django import forms
2+
from django.forms import ModelForm
3+
from . models import *
4+
5+
# naming convention: Task() is model so this is TaskForm
6+
class TaskForm(forms.ModelForm):
7+
class Meta:
8+
model= Task
9+
#
10+
fields= '__all__'
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generated by Django 4.0.3 on 2022-04-05 02:04
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
initial = True
9+
10+
dependencies = [
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name='Task',
16+
fields=[
17+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18+
('title', models.CharField(max_length=200)),
19+
('complete', models.BooleanField(default=False)),
20+
('created', models.DateTimeField(auto_now_add=True)),
21+
],
22+
),
23+
]

Code/matthew/django/lectures/08_model_forms/todo_app/migrations/__init__.py

Whitespace-only changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from django.db import models
2+
3+
# Create your models here.
4+
5+
class Task(models.Model):
6+
title= models.CharField(max_length=200)
7+
complete= models.BooleanField(default=False)
8+
created= models.DateTimeField(auto_now_add=True)
9+
10+
def __str__(self):
11+
return self.title
12+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{% extends 'todo_app/index.html' %}
2+
3+
{% block content %}
4+
5+
<p>Do you want to delete "{{item}}"</p>
6+
<form action="" method="POST">
7+
{% csrf_token %}
8+
<input type="Submit" name="Confirm">
9+
</form>
10+
<br>
11+
<a href="{% url 'index' %}">Cancel</a>
12+
{% endblock content %}

0 commit comments

Comments
 (0)