forms.py 2.41 KB
Newer Older
1 2 3 4 5 6
from django import forms
from django.forms import ModelForm, Form
from django import forms
from django.core.validators import MinValueValidator
from .models import Panier, Paiement, Commande, Credit, Livraison

7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
class NewCommandeForm(ModelForm):
    class Meta:
        model = Commande
        fields = ['quantite','date']

class BaseEditCommandeForm(NewCommandeForm):
    class Meta(NewCommandeForm.Meta):
        fields = ['quantite','date']

class FullEditCommandeForm(NewCommandeForm):
    class Meta(NewCommandeForm.Meta):
        fields = '__all__'

class SelectArticleForm(ModelForm):
    article = forms.ModelChoiceField(queryset=Panier.objects.all(), label="Articles en vente actuellement")

    class Meta:
        exclude = ['nom','prix']
        model = Panier


28 29 30
class LivraisonForm(ModelForm):
    class Meta:
        model = Livraison
31
        fields = ['date','date_modif']
32 33 34 35

    def __init__(self, *args, **kwargs):
        super(LivraisonForm, self).__init__(*args, **kwargs)
        self.fields['date'].label = 'Date de livraison'
36
        self.fields['date_modif'].label = 'Date limite de modification'
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

class DelLivraisonForm(ModelForm):
    date = forms.ModelMultipleChoiceField(queryset=Livraison.objects.all(), label="Date de livraison",  widget=forms.CheckboxSelectMultiple)

    class Meta:
        exclude = ['date']
        model = Livraison

class PaiementForm(ModelForm):
    class Meta:
        model = Paiement
        fields = ['moyen']

    def __init__(self, *args, **kwargs):
        super(PaiementForm, self).__init__(*args, **kwargs)
        self.fields['moyen'].label = 'Moyen de paiement à ajouter'

class DelPaiementForm(ModelForm):
    paiements = forms.ModelMultipleChoiceField(queryset=Paiement.objects.all(), label="Moyens de paiement actuels",  widget=forms.CheckboxSelectMultiple)

    class Meta:
        exclude = ['moyen']
        model = Paiement

Gabriel Detraz's avatar
Gabriel Detraz committed
61 62 63 64 65 66 67 68 69 70 71 72
class PanierForm(ModelForm):
    class Meta:
        model = Panier
        fields = ['nom','prix']

class DelPanierForm(ModelForm):
    paniers = forms.ModelMultipleChoiceField(queryset=Panier.objects.all(), label="Articles en vente actuellement",  widget=forms.CheckboxSelectMultiple)

    class Meta:
        exclude = ['nom','prix']
        model = Panier

73 74 75 76 77 78 79 80
class CreditForm(ModelForm):
    class Meta:
        model = Credit
        fields = ['montant','moyen','validite']

class CreditFullForm(CreditForm):
    class Meta(CreditForm.Meta):
        fields = '__all__'