当您有多对多关系(related_name而不是through)并且您尝试使用管理界面时,您需要输入其中一个关系,即使您不必存在创建第一个条目.
我正在创建一个作为活动组织者的应用程序.想象一下,我们拥有Event和Group模型,与多对多关系绑定.
Django related_name创建了另一个表,其中包含其他两个表的索引.
但我看不出为什么这个额外的表已经被填充.
如果我通过phpMyAdmin使用数据库,我可以创建一个Group没有注册的Event,因为两者之间的连接只是通过一个单独的表,并且在给定级别没有数据库值强制执行.
如何使管理界面实现呢?
如何在Django中使多对多字段可选?
我已经查看了git-scm.com和gitref.org的相关文档,但我似乎无法弄清楚这一点.
假设我希望获得2013年11月12日星期二的所有提交.以现有的repo为例,我知道我当天有提交,以及前一天和后一天的提交.
2013-11-11和2013-11-12以下所有内容都给了我11月11日和12日的承诺:
git log --after="2013-11-11" --until="2013-11-12"git log --since="2013-11-11" --until="2013-11-12"git log --after="2013-11-11" --before="2013-11-12"git log --since="2013-11-11" --before="2013-11-12"2013-11-12只以下所有内容均未给出任何提交:
git log --since="2013-11-12" --until="2013-11-12" git log --since="2013-11-12" --before="2013-11-12"git log --after="2013-11-12" --until="2013-11-12"git log --after="2013-11-12" --before="2013-11-12" 2013-11-12和2013-11-13正如预期的那样(从结果2013-11-11及2013-11-12以上),所有来自11月12日和13日以下的给我的结果:
git log --since="2013-11-12" --before="2013-11-13"git log --after="2013-11-12" --before="2013-11-13"git log --since="2013-11-12" --until="2013-11-13"git log --after="2013-11-12" --before="2013-11-13"...等等等等.我觉得我已经尝试过的每一个可能的组合since,after,before和until …
当我尝试使用命令测试任何应用程序时(当我尝试使用使用此命令的fabric部署myproject时我注意到了它):
python manage.py test appname
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Creating test database for alias 'default'...
Got an error creating the test database: permission denied to create database
Type 'yes' if you would like to try deleting the test database 'test_finance', or 'no' to cancel
Run Code Online (Sandbox Code Playgroud)
syncdb命令似乎有效.我在settings.py中的数据库设置:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'finance', # Or path to database file if using sqlite3.
'USER': 'django', # Not used with sqlite3.
'PASSWORD': 'mydb123', # Not used …Run Code Online (Sandbox Code Playgroud) 从磁盘上的版本刷新文件的命令是 :e!
如何对缓冲区中的所有文件执行相同操作?
背景:我需要这个,因为我使用带有多个分支的git,其中一个vim open包含一个缓冲区.当我结帐分支时,我想要vim刷新.
遵循这个Django by example tutotrial:http://lightbird.net/dbe/todo_list.html
教程说:
"这改变了我们的表格布局,我们必须要求Django重置并重新创建表格:
manage.py reset todo; manage.py syncdb"
但是,当我跑步时manage.py reset todo,我收到错误:
$ python manage.py reset todo
- Unknown command: 'reset'
Run Code Online (Sandbox Code Playgroud)
这是因为我使用的是sqlite3而不是postgresql吗?
有人能告诉我重置数据库的命令是什么吗?
命令:python manage.py sqlclear todo返回错误:
$ python manage.py sqlclear todo
CommandError: App with label todo could not be found.
Are you sure your INSTALLED_APPS setting is correct?
Run Code Online (Sandbox Code Playgroud)
所以我在settings.py中将'todo'添加到了我的INSTALLED_APPS,然后python manage.py sqlclear todo再次运行,导致出现此错误:
$ python manage.py sqlclear todo
- NameError: name 'admin' is not defined
Run Code Online (Sandbox Code Playgroud) 我有一个data.json文件,我正在使用python的json.tool通过命令行验证,但它不断给我一个错误消息:
$ python -m json.tool < data.json
No JSON object could be decoded
Run Code Online (Sandbox Code Playgroud)
以下是内容data.json:
$ cat data.json
{ "fields":
[
[ "first_name", null, {} ],
[ "last_name", null, {} ],
[ "addr1", null, {} ],
[ "addr2", null, {} ],
[ "city", null, {} ],
]
}
Run Code Online (Sandbox Code Playgroud)
单引号我没有问题,文件也没有空(显然),所以我不确定是什么原因引起了这个问题.
在使用virtualenvwrapper之前我从来没有看过这个消息,但现在每当我跑步时,我突然看到这个消息,mkvirtualenv <environment>或者workon <environment>:
Usage: source deactivate
removes the 'bin' directory of the environment activated with 'source
activate' from PATH.
Run Code Online (Sandbox Code Playgroud)
我根本没有修改过virtualenvwrapper,快速谷歌搜索只会产生这个GitHub问题 - 我之前安装了IPython/Anaconda,但我不确定它是如何干扰virtualenvwrapper的.在任何情况下,我都尝试更新两个(conda update conda; conda update ipython),以及将virtualenvwrapper本身更新为v4.1.1,但我仍然看到这个错误.
我正在运行OS X 10.8.4.
我正在运行最新的Raspbian发行版,只是安装了这些transmission软件包.
但是,每当我运行一个transmission-remote命令 - 比如说,改变一些基本配置 - 我都会遇到同样的错误:
$ transmission-remote -DU -c required -p 9091 -w ~/torrents
Unexpected response: <h1>401: Unauthorized</h1>Unauthorized User: deflate, gzip
Run Code Online (Sandbox Code Playgroud)
我找不到任何好的文档或教程来解决问题,我怀疑我错过了初始设置过程中导致此错误的步骤.我已经尝试过设置用户名/密码,即
$ transmission-remote --auth myusername:mypassword
Run Code Online (Sandbox Code Playgroud)
哪个成功了,但它仍然为所有其他命令抛出相同的"意外响应"错误.
开始transmission-daemon也不起作用:
$ service transmission-daemon start
[....] Starting bittorrent daemon: transmission-daemonstart-stop-daemon: unable to set gid to 110 (Operation not permitted)
failed!
Run Code Online (Sandbox Code Playgroud)
有没有人知道为什么会这样?
我正在尝试cd使用我的git根目录定义一个别名git rev-parse --show-toplevel.
目前我把它作为我的别名.bashrc,它工作正常:
alias gitroot='cd "$(git rev-parse --show-toplevel)"'
Run Code Online (Sandbox Code Playgroud)
但是我知道你可以使用git别名运行shell命令,所以我想我会把命令移到.gitconfig我的文件中以使我的文件更清晰.
问题是,我无法弄清楚为什么我的别名不起作用.目前我[alias]在我的下面有这个.gitconfig:
root = "!sh -c 'cd \"$(git rev-parse --show-toplevel)\"'"
Run Code Online (Sandbox Code Playgroud)
但是当我跑步时git root,我只是留在当前目录中.
我已经尝试过其他shell别名并且他们已经工作了,例如别名say = "!sh -c 'echo \"$0\"'"工作得很好:
$ git say hello
hello
Run Code Online (Sandbox Code Playgroud)
虽然我注意到类似的cd命令(cd = "!sh -c 'cd \"$0\"'")失败了:
~/repos/myproject$ git cd /home/
~/repos/myproject$
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚它是否与我的语法有关,或者它是git别名的怪癖,它不支持cd命令,或完全不同的东西.
如果有帮助,我正在使用Git 1.7.9.5.
我的repo使用了Recurly-js的自定义版本,我使用这些说明https://devcenter.heroku.com/articles/git-submodules将其打包为子模块.但是,当我尝试部署时,我现在收到以下错误:
----> Heroku receiving push
-----> Git submodules detected, installing
Submodule 'recurly-js' (/app/tmp/repo.git/recurly-js) registered for path 'recurly-js'
Initialized empty Git repository in /tmp/build_3iacvn8h2rnha/recurly-js/.git/
fatal: '/app/tmp/repo.git/recurly-js' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
Clone of '/app/tmp/repo.git/recurly-js' into submodule path 'recurly-js' failed
! Heroku push rejected, Submodule install failed
Run Code Online (Sandbox Code Playgroud) git ×4
python ×4
django ×3
alias ×1
anaconda ×1
buffer ×1
command-line ×1
database ×1
django-admin ×1
git-log ×1
heroku ×1
json ×1
many-to-many ×1
postgresql ×1
raspberry-pi ×1
raspbian ×1
reset ×1
shell ×1
sql ×1
transmission ×1
vim ×1