如果我有一个问答系统,并且我想添加一个标签功能,就每个问题我应该有一些标签,用逗号分隔(就像Stackoverflow一样):
我应该在表单中使用什么,以便用逗号分隔的标签保存在数据库中,每个标签都注册?(便于搜索)
谢谢
我正在使用Jquery验证引擎(https://github.com/posabsolute/jQuery-Validation-Engine)作为我的一个表单.验证工作正常,但即使字段值不符合验证,也无法阻止表单提交:
我有一份时事通讯Sigunp表格如下:
<form id="submit-newsletter" method="POST" action="">
<input type="text" class="searchform validate[required, custom[email]]" value="Enter Your Email" id="email" name="nw-email" onblur="defaultInput(this);" onfocu s="clearInput(this);" />
<input type="hidden" id="newsletter" name="newsletter" value="nl" />
<input type="submit" class="submit" title="Signup" value="Sign Up" name="newsletter-signup" onclick="newsletterSubscribe(event);" />
</form>
Run Code Online (Sandbox Code Playgroud)
此表单通过ajax提交如下:
// Newsletter Subscription Without Refresh
function newsletterSubscribe(e) {
e.preventDefault();
var dataString = 'nw-email=' + $('input[name=nw-email]').val() + '&newsletter=' + $('input[name=newsletter]').val();
$.ajax({
type: "POST",
url: "/newsletter/",
data: dataString,
success: function () {
$('#newsletter-box').html('<div id="message"></div>');
$('#message').html('<img width="18px" height="18px" src="/static/img/smtick.png" /><h5>Thank You !</h5>')
.append('<p>We have recieved your …Run Code Online (Sandbox Code Playgroud) 我正在使用webapp2_extras.appengine.auth.models.User基本上扩展的服务google.appengine.api.users model.现在,我有自己的应用程序注册的自定义用户,他们有很多自定义字段.问题是我想使用各种自定义字段过滤/(多重过滤)所有用户.例如:
用户模型有2个字段is_active,activation_key现在我想使用这些字段过滤它们,例如:
from google.appengine.api import users
act_key = 'hw-2j38he63u83hd6hak3FshSqj3TGemn9'
user = users.all().filter('is_active =', False).filter('activation_key =', act_key).get()
if user:
return True
else:
return False
Run Code Online (Sandbox Code Playgroud)
使用自定义字段过滤用户模型的最佳方法是什么?
编辑:
还尝试了以下内容:
from webapp2_extras.appengine.auth.models import User
query = User.query().filter('is_active =', False)
print query
Run Code Online (Sandbox Code Playgroud)
但这会引发如下错误:
Traceback (most recent call last):
File "/opt/google_appengine_1.6.4/google/appengine/ext/admin/__init__.py", line 320, in post
exec(compiled_code, globals())
File "<string>", line 6, in <module>
File "lib/ndb/query.py", line 968, in filter
raise TypeError('Cannot filter a non-Node argument; received %r' …Run Code Online (Sandbox Code Playgroud) 我正在开发一个Android应用程序,并在我的一个布局中有一个togglebutton(id ="tt").我想要做的是将OnClickListener设置为togglebutton.但是我在eclipse中遇到以下错误:
toggleButton cannot be resolved to a variable
onClickListener cannot be resolved to a type
Run Code Online (Sandbox Code Playgroud)
这是代码:
public void ToggleMagic(){
toggleButton = (ToggleButton)findViewById(R.id.tt);
toggleButton.setOnClickListener(new OnClickListener(){
//
});
}
Run Code Online (Sandbox Code Playgroud) 我想要做的是定义一个使用django.shortcuts.get_object_or_404和 的自定义方法select_related。我的方法定义如下:
class Sample(models.Model):
slug = models.SlugField()
# Sample class fields
Run Code Online (Sandbox Code Playgroud)
import models
from django.shortcuts import get_object_or_404
def get_sample_or_404(**kwargs):
sample = get_object_or_404(models.Sample.objects.select_related(), kwargs)
return sample
Run Code Online (Sandbox Code Playgroud)
现在,每当我尝试使用这种方法时,我都会得到get_sample() got an unexpected keyword argument 'xxxx'. 以下是我如何使用它:
sample = get_sample_or_404(slug='first-sample')
Run Code Online (Sandbox Code Playgroud)
有人能把我放在正确的方向吗?
谢谢。
我正在尝试为我的Android应用程序制作一个简单的菜单.但不知道为什么我在menu.xml文件中收到以下错误:
[2012-07-21 11:53:27 - Torchit] W/ResourceType( 5469): Bad XML block: header size 46936 or total size 163847776 is larger than data size 0
[2012-07-21 11:53:27 - Torchit] /home/tigerstyle/workspace/Torchit/res/menu/menu.xml:2: error: Error: No resource found that matches the given name (at 'id' with value '@id/menu_item_about').
Run Code Online (Sandbox Code Playgroud)
menu.xml代码如下:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@id/menu_item_about"
android:title="About"
android:icon="@drawable/menu_about" />
</menu>
Run Code Online (Sandbox Code Playgroud) 为什么我在这个简单的函数中使用+ =得到语法错误?
def downloadImages(urllist):
counter = 0
for url in urllist:
downloadSingleImage(url, (filename_prefix + str(counter))
counter += 1
Run Code Online (Sandbox Code Playgroud) 我有一个看起来像这样的模板.
<div id="form-entry">
<h4>Some heading here</h4>
<div class="form-field">
<label>Some Label</label>
<input type="text" class="some_text" />
</div>
<div class="form-field">
<label>Some Label</label>
<input type="text" class="some_text" />
</div>
<div class="form-field">
<label>Some Label</label>
<input type="text" class="some_text" />
</div>
<div class="form-field">
<input type="checkbox" />
<label>Some Label</label>
</div>
<div class="form-field">
<label>Some Label</label>
<textarea></textarea>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
如果用户选中复选框,我想删除(或隐藏)form-field包含checkbox输入的div上方的div .HTML是自动呈现的,没有任何特定的id's或classes.我该怎么做呢 请问jQuery的位置会有什么用?
$('.form-field input[type=checkbox]').click( function(){
entity = $(this);
dad = entity.parent(); // This gets the form-field div element that contains the …Run Code Online (Sandbox Code Playgroud) 我希望实现的是以特定模式排列列表中的项目.说,我有以下字典:
>>>dict_a = {
'north' : 'N',
'south' : 'S',
'east' : 'E',
'west' : 'W',
'north east' : 'NE',
'north west' : 'NW'
}
Run Code Online (Sandbox Code Playgroud)
现在检查字符串是否包含上述字典中的任何项目:
>>>string_a = 'North East Asia'
>>>list_a = []
>>>for item in dict_a:
if item in string_a.lower():
list_a.append(item)
Run Code Online (Sandbox Code Playgroud)
它给我的结果如下,这是有道理的
>>>['north', 'north east', 'east']
Run Code Online (Sandbox Code Playgroud)
但我想得到的是['north east'],忽略north和east.我怎么做到这一点?
以下条件给出相同的结果.它们之间是否有任何性能(或任何其他)差异?
1.
if (x != None) and (y != None):
# Proceed
Run Code Online (Sandbox Code Playgroud)
2.
if (x and y) is not None:
# Proceed
Run Code Online (Sandbox Code Playgroud) $('.sn').css({'z-index':'-1000'});
(隐藏整个组)加载整个班级,从那个班级我想显示或应用 css $('#item1').css({'z-index':'1000'});(只显示组中的一个),点击某个元素 dynamicaly 但这不会发生,请帮助我?当我使用 hide() 和 show() 方法时,它工作正常。
//on click ..
$(document).on('click','#slider1prev',function(){
selected = selected-1;
if(my_text != ""){
$('#noteImage'+selected).css({'z-index':'1000'});
$('#noteText'+selected).css({'z-index':'1000'});
}
});
Run Code Online (Sandbox Code Playgroud)
//负载..
$('.sn').css({'z-index':'-1000'});
$('.notes').css({'z-index':'-1000'});
Run Code Online (Sandbox Code Playgroud)