I'm trying to get a single row from my database using the "get" method in Python/Django. The model I'm using is
class SavedQuery(models.Model):
name = models.CharField(max_length = 512)
queryText = models.CharField(max_length = 2048)
created = models.DateTimeField(auto_now_add=True)
Now, I've saved some values in that database, ensuring that all of them are unique. So now I want to get the value of the queryText when given a name. I tried using the following code:
entry = SavedQuery.objects.get(name = query_name)
#query_name is an input to the function, and I've verified it is correct
The line for entry, however, does not work. I'm getting a 500 error through the browser, and the terminal I'm running the server from isn't showing any error message. The DEBUG output is incomprehensible to me as well.
My band-aid solution is to use SavedQuery.objects.all() and then go through and check the name field, but I have seen on the Django site that it's possible to get a list of objects with a certain value in a given field, so I'd rather just do that.
EDIT: Debugging output from the spot where it's messing up is
2014-06-12 19:56:20 DEBUG bolt django.db.backends util.execute:79: (0.000) SELECT `bolt_savedquery`.`id`, `bolt_savedquery`.`name`, `bolt_savedquery`.`queryText`, `bolt_savedquery`.`created` FROM `bolt_savedquery` WHERE `bolt_savedquery`.`name` = 'Kyle' ; args=(u'Kyle',)
2014-06-12 19:56:20 DEBUG bolt django.db.backends util.execute:79: (0.000) SELECT `bolt_savedquery`.`id`, `bolt_savedquery`.`name`, `bolt_savedquery`.`queryText`, `bolt_savedquery`.`created` FROM `bolt_savedquery` LIMIT 21; args=()
.getraiseMultipleObjectsReturnedorObjectDoesNotExistor something?DEBUG=Truein yoursettings.pyfile. That way you will see tracebacks in the browser rather than a 500 error...