Last bit of major changes
Closes #1 Closes #5 Closes #6 Closes #8 Closes #9 Closes #10
This commit is contained in:
@@ -35,13 +35,31 @@ class AddressForm(forms.ModelForm):
|
||||
}
|
||||
|
||||
class PaymentMethodForm(forms.ModelForm):
|
||||
card_number = forms.CharField(max_length=19, widget=forms.TextInput(attrs={'class': 'form-input', 'placeholder': 'Card Number'}))
|
||||
cvv = forms.CharField(max_length=4, widget=forms.TextInput(attrs={'class': 'form-input', 'placeholder': 'CVV'}))
|
||||
billing_address = forms.ModelChoiceField(queryset=Address.objects.none(), required=False, empty_label="Select Billing Address")
|
||||
|
||||
class Meta:
|
||||
model = PaymentMethod
|
||||
fields = ('brand', 'last4', 'exp_month', 'exp_year', 'is_default')
|
||||
fields = ('brand', 'exp_month', 'exp_year', 'billing_address', 'is_default')
|
||||
widgets = {
|
||||
'brand': forms.TextInput(attrs={'class': 'form-input', 'placeholder': 'Card Brand (e.g. Visa)'}),
|
||||
'last4': forms.TextInput(attrs={'class': 'form-input', 'placeholder': 'Last 4 Digits', 'maxlength': '4'}),
|
||||
'exp_month': forms.NumberInput(attrs={'class': 'form-input', 'placeholder': 'Exp Month', 'min': '1', 'max': '12'}),
|
||||
'exp_year': forms.NumberInput(attrs={'class': 'form-input', 'placeholder': 'Exp Year', 'min': '2024'}),
|
||||
'billing_address': forms.Select(attrs={'class': 'form-select'}),
|
||||
'is_default': forms.CheckboxInput(attrs={'class': 'form-checkbox'}),
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
user = kwargs.pop('user', None)
|
||||
super().__init__(*args, **kwargs)
|
||||
if user:
|
||||
self.fields['billing_address'].queryset = Address.objects.filter(user=user)
|
||||
|
||||
def save(self, commit=True):
|
||||
pm = super().save(commit=False)
|
||||
pm.card_number = self.cleaned_data['card_number']
|
||||
pm.cvv = self.cleaned_data['cvv']
|
||||
if commit:
|
||||
pm.save()
|
||||
return pm
|
||||
|
||||
Reference in New Issue
Block a user