Przeglądaj źródła

Set size on wishlist line quantity form field

This doesn't actually work since there is an overriding CSS style.  When
issue #851 is resolved, this should start working.
master
David Winterbottom 12 lat temu
rodzic
commit
661baf5e28
1 zmienionych plików z 11 dodań i 3 usunięć
  1. 11
    3
      oscar/apps/wishlists/forms.py

+ 11
- 3
oscar/apps/wishlists/forms.py Wyświetl plik

@@ -1,7 +1,7 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 from django import forms
3 3
 from django.db.models import get_model
4
-from django.forms.models import inlineformset_factory
4
+from django.forms.models import inlineformset_factory, fields_for_model
5 5
 
6 6
 WishList = get_model('wishlists', 'WishList')
7 7
 Line = get_model('wishlists', 'Line')
@@ -18,5 +18,13 @@ class WishListForm(forms.ModelForm):
18 18
         fields = ('name', )
19 19
 
20 20
 
21
-LineFormset = inlineformset_factory(WishList, Line, fields=('quantity', ),
22
-                                    extra=0, can_delete=False)
21
+class WishListLineForm(forms.ModelForm):
22
+
23
+    def __init__(self, *args, **kwargs):
24
+        super(WishListLineForm, self).__init__(*args, **kwargs)
25
+        self.fields['quantity'].widget.attrs['size'] = 2
26
+
27
+
28
+LineFormset = inlineformset_factory(
29
+    WishList, Line, fields=('quantity', ), form=WishListLineForm,
30
+    extra=0, can_delete=False)

Ładowanie…
Anuluj
Zapisz