我有一个具有以下文档结构的数据库:
{
"_id" : ObjectId("520bea012ab230549e749cff"),
"Day" : 1,
"Time" : 54,
"State" : "Vermont",
"Airport" : "BTV",
"Temperature" : 39,
"Humidity" : 57,
"Wind Speed" : 6,
"Wind Direction" : 170,
"Station Pressure" : 29.6,
"Sea Level Pressure" : 150
}
Run Code Online (Sandbox Code Playgroud)
我需要为每个"州"找到最高的"温度"(例如,有100个带有"州"的文件:'佛蒙特州')并添加条目'month_high':true为此文件(具有最高温度)
这是我的代码:http://pastebin.com/UbACLbSF
但是当我在shell中运行程序时,我收到以下错误:
MongoError:无法规范化查询:BadValue错误的顺序数组[2]
models.py:
from django.contrib.auth.models import User
class Location(models.Model):
user = models.ForeignKey(User)
Run Code Online (Sandbox Code Playgroud)
views.py
class UserLocationsListView(ListView):
model = Location
context_object_name = 'user_locations'
def get_queryset(self):
user_locations = Location.objects.filter(user=self.request.user)
paginator = Paginator(user_locations, 10)
page = self.request.GET.get('page')
try:
user_locations = paginator.page(page)
except PageNotAnInteger:
user_locations = paginator.page(1)
except EmptyPage:
user_locations = paginator.page(paginator.num_pages)
return user_locations
Run Code Online (Sandbox Code Playgroud)
urls.py:
url(r'^member/user_locations/$', UserLocationsListView.as_view(), name='user_locations'),
Run Code Online (Sandbox Code Playgroud)
我希望用户能够在页面上看到其所有位置。
看来我在使用REQUEST时遇到了问题(在过滤和页面定义中)
我该如何解决?
谢谢!
Environment:
Request Method: GET
Request URL: http://localhost:8000/member/user_locations/
Django Version: 1.8.6
Python Version: 2.7.11
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount', …Run Code Online (Sandbox Code Playgroud) 请麻烦帮忙:
class SearchResultView(TemplateView):
template_name = "search_result.html"
def get_context_data(self, **kwargs):
context = super(SearchResultView, self).get_context_data(**kwargs)
location = self.request.GET['location']
locations_searched = Location.objects.filter(name__icontains=location)
context['locations_searched'] = locations_searched
return context
class AdvancedSearchForm(forms.Form):
location = forms.CharField(label=u"???????:")
Run Code Online (Sandbox Code Playgroud)
在“位置”字段中输入大写单词时,我可以在视图中看到结果,但是如果没有大写,则视图中不会显示任何内容
谢谢!