I'm trying to query an object and when I hard code the value it works but when I use a variable for it the query doesn't work.
Here's the class:
class AdvertisementType(models.Model):
type = models.CharField(max_length='40')
description = models.CharField(max_length='80')
def __unicode__(self):
return '%s' % self.type
Here's the query:
self.type_ad = AdvertisementType.objects.get(type=type_of_ad)
As an example, there is an AdvertisementType where the type="Inner Page"
When I use this statement:
self.type_ad = AdvertisementType.objects.get(type="Inner Page")
Everything works fine but if I do
self.type_ad = AdvertisementType.objects.get(type=type_of_ad)
I get the error
Caught an exception while rendering: AdvertisementType matching query does not exist.
even when type_of_ad = "Inner Page"
Any ideas?