models.py 1.48 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
from django.db import models

from django.forms import ModelForm, Form
from django.db.models.signals import post_save, post_delete
from django.dispatch import receiver


class Panier(models.Model):
    prix = models.DecimalField(max_digits=5, decimal_places=2)
    nom = models.CharField(max_length=255)

Gabriel Detraz's avatar
Gabriel Detraz committed
12 13 14
    def __str__(self):
        return self.nom

15 16
class Commande(models.Model):
    user = models.ForeignKey('users.User', on_delete=models.PROTECT)
17
    nom = models.CharField(max_length=255)
18
    quantite = models.IntegerField()
19
    prix_unitaire = models.DecimalField(max_digits=5, decimal_places=2)
20 21 22
    livre = models.BooleanField(default=False)  
    date = models.ForeignKey('Livraison', on_delete=models.PROTECT)

23 24 25
    def prix(self):
        return self.prix_unitaire*self.quantite

26 27 28 29
class Credit(models.Model):
    user = models.ForeignKey('users.User', on_delete=models.PROTECT)
    montant = models.DecimalField(max_digits=5, decimal_places=2)
    moyen = models.ForeignKey('Paiement', on_delete=models.PROTECT)
30
    validite = models.BooleanField(default=True)
31 32

    def __str__(self):
33
        return str(self.montant) + "€ pour " +  str(self.user)
34 35

class Paiement(models.Model):
36
    moyen = models.CharField(max_length=255, unique=True)
37 38 39 40 41

    def __str__(self):
        return self.moyen

class Livraison(models.Model):
42
    date = models.DateTimeField(help_text='%d/%m/%y %H:%M:%S')
43
    date_modif = models.DateTimeField(help_text='%d/%m/%y %H:%M:%S')
44 45 46

    def __str__(self):
        return str(self.date)