working through jim mcgaws ecommerce book).
in the view
if product.has_options:
form = ProductSizeOptionsAddToCartForm(request=request,
label_suffix=':')
else:
form = ProductAddToCartForm(request=request, label_suffix=':')
then in the forms.py
def create_choices():
if self.product:
options = self.product.options
output = [u'(']
for k, v in self.product.options:
option_value = smart_unicode(k)
option_label = smart_unicode(v)
output.append(u"('%s','%s'),")
output.append(')')
return output
class ProductSizeOptionsAddToCartForm(forms.Form):
quantity =
forms.IntegerField(widget=forms.TextInput(attrs={'size':'2',
'value':'1', 'class':'quantity', 'maxlength':'5'}),
error_messages={'invalid':'Please enter a valid quantity.'},
min_value=1)
size_option =
forms.CharField(widget=forms.Select(choices=create_choices))
product_slug = forms.CharField(widget=forms.HiddenInput())
I have tried to write a function that is called from the Select widget
and i get the "'function' object is not iterable" error message, which
is quite obvious. what if every product doesn't have the same options
as CLOTHING_CHOICES list? I've been trying to work out how to store
the options in the db (product.options as a comma separated CharField)
and then pass them into the form as part of the product view.
Anyone done anything like this?
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment