一般性问题.我正在为Sybase SQL Anywhere 10开发.出于向后兼容性原因,几乎所有存储过程都是用Transact-SQL编写的.使用T-SQL而不是Watcom方言有什么优点或缺点吗?
以前,我使用了这个查询,速度很快:
cb=# explain analyze SELECT "web_route"."id", "web_crag"."id" FROM "web_route"
INNER JOIN "web_crag" ON ( "web_route"."crag_id" = "web_crag"."id" )
WHERE "web_crag"."type" IN (1, 2)
ORDER BY "web_crag"."name" ASC
LIMIT 20;
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=0.00..2.16 rows=20 width=18) (actual time=0.027..0.105 rows=20 loops=1)
-> Nested Loop (cost=0.00..47088.94 rows=436055 width=18) (actual time=0.026..0.100 rows=20 loops=1)
-> Index Scan using web_crag_name on web_crag (cost=0.00..503.16 rows=1776 width=14) (actual time=0.011..0.020 rows=14 loops=1)
Filter: (type = ANY ('{1,2}'::integer[]))
-> Index Scan using web_route_crag_id on web_route (cost=0.00..23.27 rows=296 width=8) (actual …Run Code Online (Sandbox Code Playgroud) 我是Django的新手,似乎有一种简单而明显的方法可以做到这一点,但如果是这样,我就无法找到它.
(稍微简化的代码)
我有一个小学班
class Article(models.Model):
...
Run Code Online (Sandbox Code Playgroud)
和一个中学课
class Headline(models.Model):
article = models.ForeignKey(Article)
headline = models.CharField(max_length=200)
Run Code Online (Sandbox Code Playgroud)
有没有一种简单的方法来获取对象的headline属性Article(或者更确切地说,获取headline与Headline对象关联的所有对象的Article属性)?我知道可以Headline按article属性过滤对象,但我怀疑有更快更简单的方法.例如,是否可以向类中添加一个Article返回所有关联Headline对象的方法?
我在使用Django的表单上遇到Unicode输入问题:
UnicodeEncodeError at /
'ascii' codec can't encode character u'\xe4' in position 7: ordinal not in range(128)
Run Code Online (Sandbox Code Playgroud)
这种情况发生在gunicorn上,以及在调试模式下运行Django.我的form.py启用了unicode:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from django import forms
from django.core.mail import send_mail
from django.core.mail import EmailMessage
import datetime
class RTForm(forms.Form):
# ...
institution_station = forms.CharField(max_length=75, label=u"Institute/Station*")
# ...
Run Code Online (Sandbox Code Playgroud)
视图是基于此创建的,目的是从输入构建电子邮件:
class RTview(FormView):
template_name = 'rt-form.html'
form_class = RTForm
success_url = '/thanks/'
def form_valid(self, form):
# This method is called when valid form data has been POSTed.
# It should return an …Run Code Online (Sandbox Code Playgroud) 我正在运行Django 1.6.x.
为了扩展我的用户,我添加了另一个存储数据的模型:
class UserProfile (models.Model):
user = models.ForeignKey(User)
height = models.IntegerField(blank=True, null=True)
Run Code Online (Sandbox Code Playgroud)
现在我想添加一个视图,允许用户在那里添加自己的信息.开始django.views.generic.edit.CreateView,但也想提供至少编辑/更新一个.
所以我添加了导入并创建了一个视图:
from django.views.generic.edit import CreateView, UpdateView
# ....
class UserProfileCreateView(CreateView):
model = UserProfile
fields = ['height']
Run Code Online (Sandbox Code Playgroud)
我还在urls.py中添加了条目:
url(r'^userprofile/new/$', login_required(UserProfileCreateView.as_view()), name="add_userprofile")
Run Code Online (Sandbox Code Playgroud)
但现在我仍然坚持如何以正确的方式分配用户ID.我希望在后台设置此字段.任何提示?
我有这个简单的mysql查询:
INSERT INTO table (col1, col2) VALUES ('1', '2')
Run Code Online (Sandbox Code Playgroud)
col1和col2外键的另一个表,以便对任何价值col1和col2必须存在于其他表或其他行不会被插入.
在这种情况下,是否还存在SQL注入的风险?如果我从PHP POST收到这些col值,在插入数据库之前是否还需要绑定它们,或者它们已经安全,因为cols是外键?
从views.py我发送到模板2数组:
['cat','dog','mause']['one','two','three']模板:
{% for value in animal %}
animal:{{ value }} \ how meny {{ how_many[(forloop.counter0)] }}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
在for循环中,我想读取一个迭代,然后在第二个数组中使用它,但我无法让它工作.我是初学者.
这种情况的正确缩进是什么:
class StorageType(models.Model):
""" Defining a general typ of storage """
name = models.CharField(
max_length=50,
help_text=_("The name for a storage type. Should be unique")
)
Run Code Online (Sandbox Code Playgroud)
pep8抱怨
../models.py:68:13: E126 continuation line over-indented for hanging indent
../models.py:70:9: E121 continuation line under-indented for hanging indent
Run Code Online (Sandbox Code Playgroud) 我在我的任务中尝试过这个,但似乎不起作用
- name: Fix line endings from CRLF to LF
local_action: replace dest={{my_dir}}/conf/{{item}} regexp='\r\n' replace='\n'
Run Code Online (Sandbox Code Playgroud)
我通常使用 sed 执行此操作,如下所示,它有效
sed -i 's/\r//g' file
Run Code Online (Sandbox Code Playgroud)
我想避免使用 shell 模块来进行此替换,因为它会在 ansible 中引发警告
您不应该在Python中使用超过80个字符的行.但我想知道如何导入长线,例如
from .exceptions import PartsNotFitException, PartsmanagementException, CircleDetectedException
Run Code Online (Sandbox Code Playgroud)
我在想
from .exceptions import PartsNotFitException
from .exceptions import PartsmanagementException
from .exceptions import CircleDetectedException
Run Code Online (Sandbox Code Playgroud)
但不知何故,这看起来很奇怪.
django ×5
python ×5
pep8 ×2
sql ×2
ansible ×1
import ×1
linux ×1
mysql ×1
optimization ×1
postgresql ×1
security ×1
sed ×1
sqlanywhere ×1
unicode ×1