So, I'm working on a bar tab application in Django, and when it came down to insert some data into the tabs I'm getting the error:
ValueError at /tabs/345/add/Caipirinha/
invalid literal for int() with base 10: '345/add/Caipirinha'
I have tried some of the solutions provided before on Stackoverflow but with no success.
Here are some of my files:
models.py
class Tab(models.Model):
number = models.IntegerField()
name = models.CharField(max_length='50')
tabdate = models.DateTimeField('date created')
consumed = models.ManyToManyField(Product, through='ConsumedRelation')
def __unicode__(self):
return self.name
class ConsumedRelation(models.Model):
tab = models.ForeignKey(Tab)
product = models.ForeignKey(Product)
count = models.PositiveIntegerField(blank=True, null=True, default=1)
def __unicode__(self):
return str(self.tab) + " | " + str(self.count) + " " + str(self.product)
views.py
def addproduct(request, tabnumber, product):
tabnumber = Tab.objects.get(number=number)
productadd = Product.objects.get(name=str(product))
add = ConsumedRelation.objects.create(product=productadd, tab=tabnumber, count=1)
add.save()
context = {'tabnumber': tabnumber, 'product': productadd}
return render_to_response('addproduct.html', context, context_instance=RequestContext(request))
addproduct.html
{% for product in productlist %}
<a href="add/{{ product }}/"<li>{{ product }}</li></a>
{% endfor %}
urls.py
url(r'^tabs/add/(?P<tabnumber>\d)/(?P<product>\d)/$', 'barcomandas.views.addproduct'),
I appreciate the help!