diff --git a/comet/account/migrations/0004_auto_20181214_1844.py b/comet/account/migrations/0004_auto_20181214_1844.py new file mode 100644 index 0000000..64f1621 --- /dev/null +++ b/comet/account/migrations/0004_auto_20181214_1844.py @@ -0,0 +1,24 @@ +# Generated by Django 2.1.4 on 2018-12-14 18:44 + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('account', '0003_auto_20181213_2248'), + ] + + operations = [ + migrations.AddField( + model_name='sale', + name='date', + field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='Date'), + ), + migrations.AlterField( + model_name='sale', + name='price', + field=models.DecimalField(decimal_places=2, max_digits=4, verbose_name='Prix (€)'), + ), + ] diff --git a/comet/account/models.py b/comet/account/models.py index 63a4abb..c71a2ff 100644 --- a/comet/account/models.py +++ b/comet/account/models.py @@ -1,5 +1,7 @@ from django.db import models +from django.utils import timezone + class Account(models.Model): """Account for a member.""" balance = models.DecimalField( @@ -27,6 +29,7 @@ class Sale(models.Model): ) account = models.ForeignKey(Account, on_delete=models.SET_NULL, null=True) title = models.CharField(max_length=255, verbose_name="Intitulé") + date = models.DateTimeField(verbose_name="Date", default=timezone.now) class Article(models.Model): """An article which can be sold.""" diff --git a/comet/account/templates/account/balance.html b/comet/account/templates/account/balance.html index 6d55781..cf1dc99 100644 --- a/comet/account/templates/account/balance.html +++ b/comet/account/templates/account/balance.html @@ -5,14 +5,17 @@ Remettre le solde à 0 Recharger le compte
+

Ventes

+ - {% for sale in account.sale_set.all %} + {% for sale in sales %} + diff --git a/comet/account/views.py b/comet/account/views.py index 0b2ce17..e6de136 100644 --- a/comet/account/views.py +++ b/comet/account/views.py @@ -126,6 +126,7 @@ def search(request): @login_required def account(request, pk): account = get_object_or_404(Account, pk=pk) + sales = account.sale_set.order_by('-pk') return render( request, 'account/balance.html',
Date Titre Prix
{{sale.date|date:'d/m/Y'}} {{sale.title}} {{sale.price}}