Shopping List finished

This commit is contained in:
Peter Kotyczka 2024-02-23 14:26:25 +01:00
parent 377291fdf1
commit fdd367de8d
38 changed files with 83 additions and 17 deletions

View File

@ -18,3 +18,9 @@ python3 manage.py migrate
-- Django calling Rest Services ? -- Django calling Rest Services ?
python3 manage.py runserver python3 manage.py runserver
-- Django DB Initialisation
# creating the model
python3 manage.py makemigrations
# creating the table
python3 manage.py migrate

Binary file not shown.

View File

@ -1,3 +1,5 @@
from django.contrib import admin from django.contrib import admin
from migration.models import ShoppingItem
# Register your models here. # Register your models here.
admin.site.register(ShoppingItem)

View File

@ -0,0 +1,33 @@
# Generated by Django 5.0.2 on 2024-02-23 10:59
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Product',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=120)),
('content', models.TextField(blank=True, null=True)),
('price', models.DecimalField(decimal_places=2, default=99.99, max_digits=15)),
],
),
migrations.CreateModel(
name='ShoppingItem',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateField(default=datetime.date.today)),
('name', models.CharField(max_length=120)),
('done', models.BooleanField(default=False)),
],
),
]

View File

@ -1,6 +1,15 @@
from django.db import models from django.db import models
from datetime import date
# Create your models here.
class ShoppingItem(models.Model):
created_at = models.DateField(default=date.today)
name = models.CharField(max_length=120)
done = models.BooleanField(default=False)
def __str__(self):
return str(self.id) + ' - ' + self.name
class Product(models.Model): class Product(models.Model):
title = models.CharField(max_length=120) title = models.CharField(max_length=120)
content= models.TextField(blank=True, null=True) content= models.TextField(blank=True, null=True)

View File

@ -7,26 +7,28 @@
<style> <style>
header { header {
background-color: green; background-color: green;
display: flex;
padding-left: 20px;
} }
body { body {
font-family: 'Open Sans', sans-serif; font-family: 'Open Sans', sans-serif;
background-color: #345688; background-color: white;
} }
button { button {
height: 40px; height: 40px;
width: 40 px; width: 40 px;
border-radius: 50%;
} }
.list-item { .list-item {
font-size: 32 px; font-size: 32 px;
background-color: white; background-color: white;
height: 60px; height: 30px;
box-shadow: 2px 2px 2px rgba(0,0,0,0.01);
display: flex; display: flex;
alirgn-items: center; align-items: center;
right: 16px;
bottom: 60px;
} }
</style> </style>
</head> </head>
@ -34,14 +36,25 @@
<header> <header>
<h1>Migration Apis</h1> <h1>Migration Apis</h1>
</header> </header>
{% for item in all_items %}
<div class="list-item"> <div class="list-item">
<input type="checkbox"> Element 1 <input type="checkbox"> {{item.name}}
</div> </div>
<div class="list-item"> {% endfor %}
<input type="checkbox"> Element 2 <button onclick="addItem()">+</button>
</div> <script>
<button> function addItem() {
+ let itemName = prompt('Neues Element hinzufügen');
</button> let token = '{{csrf_token}}';
let formData = new FormData();
formData.append('itemName',itemName);
formData.append('csrfmiddlewaretoken',token);
fetch('/migration/', {
method: 'POST',
body: formData
});
window.location.reload();
}
</script>
</body> </body>
</html> </html>

View File

@ -1,5 +1,5 @@
from django.urls import path from django.urls import path
from . import views from migration import views
urlpatterns = [ urlpatterns = [
path("", views.index, name= "index"), path("", views.index, name= "index"),

View File

@ -1,14 +1,17 @@
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse, JsonResponse from django.http import HttpResponse, JsonResponse
from migration.models import ShoppingItem
def index(response): def index(response):
return HttpResponse("Welcome to siMed Migration") return HttpResponse("Welcome to siMed Migration")
def migration_home(request): def migration_home(request):
return render(request,'migration.html') if request.method == 'POST':
print('Received Data',request.POST['itemName'])
ShoppingItem.objects.create(name= request.POST['itemName'])
all_items = ShoppingItem.objects.all()
return render(request,'migration.html',{'all_items': all_items})
def api_home(request,endpoint, params={"message": "Your JSON Repsonse"}): def api_home(request,endpoint, params={"message": "Your JSON Repsonse"}):
body = request.body body = request.body
data = {} data = {}