[Answer]-Django eCommerce advice

1👍

No, that’s not the way it works. You can’t use a model object as the ID property in a select widget. And you definitely shouldn’t be doing gets inside the form declaration.

Instead you should use a ModelChoiceField, with the queryset pointing to the MemoryCard model:

memory_card = forms.ModelChoiceField(queryset=MemoryCard.objects.all())

if you have more memory card options that you don’t want to show here, you could narrow it down:

memory_card = forms.ModelChoiceField(queryset=MemoryCard.objects.filter(name__in=['eight', 'sixteen', 'thirtytwo'])

Leave a comment