我有一个带有ModelChoiceField的表单,我想从我的数据库中加载一个表.如果我在表单的init上使用此查询集,那么我的视图的form.is_valid工作正常:
self.fields['categoria_formfield'].queryset = sitio_categoria.objects.exclude(categoria='patrimonio').values_list('idCategoria',flat=True)
Run Code Online (Sandbox Code Playgroud)
该代码显示了ModelChoiceField上的id列表,但我需要它来显示类别列表.所以我使用:
self.fields['categoria_formfield'].queryset = sitio_categoria.objects.exclude(categoria='patrimonio').values_list('categoria',flat=True)
Run Code Online (Sandbox Code Playgroud)
但是使用此代码.is_valid不会验证,我会收到一个表单错误:"选择一个有效的选择.这个选择不是可用的选择之一." 关于可能出现什么问题的一些线索?
模型
class sitio_categoria(models.Model):
idCategoria = models.AutoField(primary_key=True)
categoria = models.CharField(max_length=30, null=False, unique=True)
Run Code Online (Sandbox Code Playgroud)
形成
class anadirComercioPaso1_form(forms.Form):
categoria_formfield = forms.ModelChoiceField(widget=forms.Select(attrs={'size':'13', 'onchange':'this.form.action=this.form.submit()'}), queryset=sitio_categoria.objects.none())
def __init__(self, *args, **kwargs):
super(anadirComercioPaso1_form, self).__init__(*args,**kwargs)
self.fields['categoria_formfield'].queryset = sitio_categoria.objects.exclude(categoria='patrimonio').values_list('categoria',flat=True)
Run Code Online (Sandbox Code Playgroud) 我从1.9迁移到2.2并阅读文档我惊讶地发现在批量操作期间不可能进行升级,因为操作不允许选项.
bulkOps.Add(new UpdateOneModel<BsonDocument>(filter, update));
collection.BulkWrite(bulkOps);
Run Code Online (Sandbox Code Playgroud)
应该
options.isUpsert = true;
bulkOps.Add(new UpdateOneModel<BsonDocument>(filter, update, options));
collection.BulkWrite(bulkOps);
Run Code Online (Sandbox Code Playgroud)
这项工作正在进行中,有意或者我遗失了什么?谢谢.
我生成了一个夹具:
python manage.py dumpdata --all > ./mydump.json
Run Code Online (Sandbox Code Playgroud)
我使用以下方法清空所有数据库:
python manage.py sqlflush | psql mydatabase -U mydbuser
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用loaddata时:
python manage.py loaddata ./mydump.json
Run Code Online (Sandbox Code Playgroud)
我收到了这个错误:
IntegrityError: Could not load tastypie.ApiKey(pk=1): duplicate key
value violates unique constraint "tastypie_apikey_user_id_key"
DETAIL: Key (user_id)=(2) already exists.
Run Code Online (Sandbox Code Playgroud)
我在制作上遇到了这个问题而且我没有想法.有人有类似的问题吗?
我正试图从这里运行这个简单的代码
import 'package:angular/angular.dart';
void main() {
ngBootstrap();
}
Run Code Online (Sandbox Code Playgroud)
但我收到这个错误:
The function 'ngBootstrap' is not defined
Run Code Online (Sandbox Code Playgroud)
关于发生了什么的任何想法?我已经尝试过'pub get'.
我正在将一个meteor项目部署到beanstalk应用程序,但我收到错误:
Script /opt/elasticbeanstalk/hooks/appdeploy/enact/50start.sh
failed with returncode 1
Run Code Online (Sandbox Code Playgroud)
在/var/log/directory-hooks-executor.log中,我发现:
status: Unknown job: nodejs
Failed to find status of job.
Traceback (most recent call last):
File "/opt/elasticbeanstalk/containerfiles/ebnode.py", line 599, in <module>
main()
File "/opt/elasticbeanstalk/containerfiles/ebnode.py", line 583, in main
nodejs_upstart.start()
File "/opt/elasticbeanstalk/containerfiles/ebnode.py", line 199, in start
raise e
Exception: Failed to run command: None
Run Code Online (Sandbox Code Playgroud)
我正在运行运行Node.js的64位Amazon Linux 2014.03 v1.1.0任何想法的原因?
我正在关注官方文档以提供静态文件,但我在开发控制台中收到错误404.我正在使用'django.contrib.staticfiles',因此应该自动提供静态文件.这是我的设置:
设置:
STATIC_ROOT = ''
STATIC_URL = '/static/'
Run Code Online (Sandbox Code Playgroud)
模板标题:
{% load staticfiles %}
<link rel="stylesheet" href="{% static "css/app.css" %}">
Run Code Online (Sandbox Code Playgroud)
目录树:
django_project
\apps
\static
\css
app.css
\templates
index.html
Run Code Online (Sandbox Code Playgroud)
我可以在firefox控制台中看到我文件的路径是正确的:
所以问题必须是Django不提供静态文件.我找不到我所缺少的东西.任何建议都非常受欢迎.