user3592255 user3592255 - 8 months ago 34
Python Question

Django model is present, says not defined when running code

i have the following model:

class Basestationreport(models.Model):
gpstimeanddate = models.DateTimeField(db_column='GPSTimeAndDate') # Field name made lowercase.

And code:

from .models import Basestationreport

def getbasestationsbetween(request):
fromdate = request.POST.get('from')
todate = request.POST.get('to')
result = Basestationreport.objects.filter(gpstimeanddate >, 1, 1))
return HttpResponse(json.dumps(request.POST), content_type="application/json")

The error i get is:

NameError: name 'gpstimeanddate' is not defined.

My other functions which use other fields from this table work fine. Am I missing something?


The error is because its looking for a local variable called gpstimeanddate which you obviously haven't defined, nor are trying to use.

Since you're trying to use it as a field to filter results on you need to use it as a keyword in fiter, as well as use __gt

.filter(, 1, 1))