diff --git a/django/didgeridoo/webshop/forms.py b/django/didgeridoo/webshop/forms.py index 5e431a9..680f7a8 100644 --- a/django/didgeridoo/webshop/forms.py +++ b/django/didgeridoo/webshop/forms.py @@ -8,7 +8,7 @@ class RegistrationForm(forms.Form): first_name = forms.CharField() last_name = forms.CharField() street_name = forms.CharField() - street_number = forms.CharField() + street_number = forms.CharField(max_length=4) zip_code = forms.IntegerField(min_value=1000, max_value=9999) city = forms.CharField() @@ -51,3 +51,10 @@ class PictureForm(forms.ModelForm): class Meta: model = Picture fields = ['name', 'article', 'image'] + + +class AddToCartForm(forms.Form): + amount = forms.IntegerField( + label='Amount in piece.', + help_text="Enter a Value between 1 and 99.", + initial=1) diff --git a/django/didgeridoo/webshop/models.py b/django/didgeridoo/webshop/models.py index a17e7dc..a17cb65 100644 --- a/django/didgeridoo/webshop/models.py +++ b/django/didgeridoo/webshop/models.py @@ -3,6 +3,7 @@ from django.core.validators import MinValueValidator from django.db import models from django.contrib.auth.models import User from django.utils import timezone +from currencies.models import ExchangeRate class Option(models.Model): @@ -22,7 +23,6 @@ class ArticleStatus(models.Model): return self.name -# Create your models here. class Category(models.Model): name = models.CharField(max_length=200, unique=True) parent_category = models.ForeignKey('self', null=True, blank=True) @@ -50,6 +50,7 @@ class Article(models.Model): class OrderStatus(models.Model): + """ Warehouse Items have Status like ordered or out of Stock """ name = models.CharField(max_length=200, unique=True) def __str__(self): @@ -57,6 +58,7 @@ class OrderStatus(models.Model): class OrderOfGoods(models.Model): + """ Warehouse operations """ article = models.ForeignKey(Article) amount = models.FloatField(max_length=5) delivery_date = models.DateField() @@ -68,6 +70,7 @@ class OrderOfGoods(models.Model): class Picture(models.Model): + """ Pictures in relationship to Articles """ name = models.CharField(max_length=200) article = models.ForeignKey(Article) image = models.ImageField(upload_to="images") @@ -77,13 +80,15 @@ class Picture(models.Model): class Order(models.Model): + """ Submitted Orders """ user = models.ForeignKey(User, on_delete=models.CASCADE) - article = models.ManyToManyField(Article, through='OrderPosition') status = models.ForeignKey(OrderStatus) date = models.DateTimeField(default=timezone.now) + exchange_rate = models.ForeignKey(ExchangeRate) class OrderPosition(models.Model): + """ Items in Submitted Orders""" article = models.ForeignKey(Article, on_delete=models.CASCADE) order = models.ForeignKey(Order, on_delete=models.CASCADE) amount = models.FloatField(max_length=5) @@ -94,14 +99,21 @@ class OrderPosition(models.Model): class ShoppingCart(models.Model): - name = models.CharField(max_length=200) + """ Cart to User Relationships """ + name = models.CharField(max_length=200, null=True) user = models.ForeignKey(User, on_delete=models.CASCADE) - article = models.ManyToManyField(Article) def __str__(self): return self.name +class CartPosition(models.Model): + """ Items in Cart """ + article = models.ForeignKey(Article, on_delete=models.CASCADE) + amount = models.FloatField(max_length=5) + cart = models.ForeignKey(ShoppingCart, on_delete=models.CASCADE) + + class City(models.Model): name = models.CharField(max_length=200) zip_code = models.PositiveSmallIntegerField() diff --git a/django/didgeridoo/webshop/templates/webshop/article_details.html b/django/didgeridoo/webshop/templates/webshop/article_details.html index 8703063..a16a642 100644 --- a/django/didgeridoo/webshop/templates/webshop/article_details.html +++ b/django/didgeridoo/webshop/templates/webshop/article_details.html @@ -6,6 +6,15 @@

Stock: {{ article.stock }}

Status: {{ article.status }}

Price: {{ article.price_in_chf }} {{ currency_name }}

+ {% if user.is_authenticated %} +
+ {{ amount.as_p }} + + {% csrf_token %} +
+ {% else %} +

please login to fill your basket...

+ {% endif %} {% for picture in picture_list %}

{% endfor %} diff --git a/django/didgeridoo/webshop/templates/webshop/cart.html b/django/didgeridoo/webshop/templates/webshop/cart.html new file mode 100644 index 0000000..637d524 --- /dev/null +++ b/django/didgeridoo/webshop/templates/webshop/cart.html @@ -0,0 +1,32 @@ +{% extends "webshop/base.html" %} +{% block section_title %}

Cart

{% endblock %} +{% block content %} +

List of Items in your Shopping Cart:

+ {% if articles_list %} + + + + + + + + + {% for article in articles_list %} + + + + + + + + {% endfor %} +
IDNAMESTOCKAMOUNTPRICE
{{ article.id }} + + {{ article.article.name }} + {{ article.article.stock }}{{ article.amount }}{{ article.article.price_in_chf }} {{ currency_name }}
+ {% else %} +

+ There are currently no articles in your cart. +

+ {% endif %} +{% endblock %} diff --git a/django/didgeridoo/webshop/templates/webshop/nav.html b/django/didgeridoo/webshop/templates/webshop/nav.html index 9b01f06..f65151f 100644 --- a/django/didgeridoo/webshop/templates/webshop/nav.html +++ b/django/didgeridoo/webshop/templates/webshop/nav.html @@ -6,26 +6,18 @@ HOME