I get get error invalid literal for int() with base 10: '1,303' and it shows the blow code at fault. The old data works fine, its just for new stuff i add to the database. Any ideas?
def get(self, request, *args, **kwargs):
cart = self.get_object()
item_id = request.GET.get("item")
delete_item = request.GET.get("delete", False)
flash_message = ""
item_added = False
if item_id:
item_instance = get_object_or_404(Variation, id=item_id) ...
qty = request.GET.get("qty", 1)
try:
if int(qty) < 1:
delete_item = True
except:
raise Http404
This is why you should use django forms instead of pulling data direct off request.GET or request.POST. Django forms provide you with data validation which helps you avoid this kind of thing. The problem is the extra ',' in your supposed int.
int('1,303')
Will produce the error above. The following will not:
int('1,303'.replace(',',''))
So the obvious remedy then is to pass your int through such a filter.
item_instance = get_object_or_404(Variation, id=int(item_id.replace(',',''))