基础帐户
class BaseAccount(models.Model):
user = models.ForeignKey(User, unique=True)
def __unicode__(self):
"""
Return the unicode representation of this customer, which is the user's
full name, if set, otherwise, the user's username
"""
fn = self.user.get_full_name()
if fn:
return fn
return self.user.username
def user_name(self):
"""
Returns the full name of the related user object
"""
return self.user.get_full_name()
def email(self):
"""
Return the email address of the related user object
"""
return self.user.email
def is_store(self):
#try:
# self.user.is_store
# return True
#except ObjectDoesNotExist:
# …Run Code Online (Sandbox Code Playgroud) 通常,如果我正在写一个sql语句,我会做这样的事情,
SELECT * FROM (django_baseaccount LEFT JOIN django_account ON django_baseaccount.user_id = django_account.baseaccount_ptr_id)
LEFT JOIN django_address ON django_account.baseaccount_ptr_id = django_address.user_id;name
Run Code Online (Sandbox Code Playgroud)
我如何把这个用于使用API查询数据库的Djagno方式,即
TradeDownloads.objects.filter(online=1)[:6]
Run Code Online (Sandbox Code Playgroud)
我的模特基础帐户
class BaseAccount(models.Model):
user = models.ForeignKey(User, unique=True)
def __unicode__(self):
"""
Return the unicode representation of this customer, which is the user's
full name, if set, otherwise, the user's username
"""
fn = self.user.get_full_name()
if fn:
return fn
return self.user.username
def user_name(self):
"""
Returns the full name of the related user object
"""
return self.user.get_full_name()
def email(self):
"""
Return the …Run Code Online (Sandbox Code Playgroud) 使用jQuery我试图确定是否<div>有内容,或者,如果它确实那么我想什么都不做,但如果没有,那么我想添加display:none到它或.hide().以下是我的想法,
if ($('#left-content:contains("")').length <= 0) {
$("#left-content").css({'display':'none'});
}
这根本不起作用,如果div没有内容然后它只是出现,可以提出任何建议吗?
我正在使用基于Django背面构建的Python站点(非常棒的框架,无法让我的头脑绕过python),我希望拆分从数据库返回的字符串,我希望它在第一个空格出现时被拆分所以我试过这样的事,
{{product.name.split(' ' ,1)}}
Run Code Online (Sandbox Code Playgroud)
这不起作用,我得到这个堆栈跟踪,
Environment:
Request Method: GET
Request URL: http://website.co.uk/products/
Django Version: 1.1.1
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'website.news',
'website.store_locator',
'website.css_switch',
'website.professional',
'website.contact',
'website.shop',
'tinymce',
'captcha']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware')
Template error:
In template /var/www/website/src/website/shop/templates/category.html, error at line 6
Could not parse the remainder: '(' ',1)' from 'product.name.split(' ',1)'
1 : {% extends "shopbase.html" %}
2 : {% block pageid %}shop{%endblock%}
3 : {% block right-content %}
4 : <div class="products">
5 …Run Code Online (Sandbox Code Playgroud) class person {
var $name;
var $email;
//Getters
function get_name() { return $this->name; }
function get_email() { return $this->email; }
//Setters
function set_name( $name ) { $this->name = $name; }
function set_email( $email ) {
if ( !eregi("^([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*[@]([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*[.]([0-9,a-z,A-Z]){2}([0-9,a-z,A-Z])*$", $email ) ) {
return false;
} else {
$this->email = $email;
return true;
}
}//EOM set_email
}//EOC person
Run Code Online (Sandbox Code Playgroud) 我目前正在使用python/django网站,目前我有一个看起来像这样的模板
{% extends "shopbase.html" %}
{% block pageid %}products{% endblock %}
{% block right-content %}
<img src="{{MEDIA_URL}}/local/images/assets/products.png" alt="Neal and Wolf News" class="position"/>
<div class="products">
<form method="post" action="{% url category category.slug %}">
{% for product in category.products.all %}
<div class="{% cycle 'clear' '' '' %}">
<img src="{{MEDIA_URL}}{{download.mini.thumbnail}}" alt="{{product.name}}" class="thumbnail"/>
<h3><a href="{% url shop.views.product category.slug product.slug %}">{{ product.product_type_name }}</a></h3>
<p class="strap">{{ product.product_sub_name }}</p>
<p>{{ product.strap }}</p>
<ul class="clear">
<li class="price"><b>£{{product.price}}</b></li>
<li class="quantity">
<select name="quantity_{{product.id}}">
<option label="1" value="1">1</option>
<option label="2" value="2">2</option>
<option label="3" …Run Code Online (Sandbox Code Playgroud) 我目前正在codeigniter中建立一个网站,这是一个页面网站,基本上是一个用户进入页面,他们使用该菜单中的主菜单创建,他们选择了他们想要查看的网站的哪些部分,并点击关联链接...点击这些链接应该在他们自己的手册菜单中显示内容.
我的问题是我认为最简单的方法是使用jquery和ajax加载选定的视图?如果我在错误的路线上什么是更好的解决方案,我也找不到任何关于使用ajax加载视图的内容,是否有人有任何建议?
当我尝试在我的Python网站上查看一些数据时,我有这个堆栈跟踪错误,有人可以告诉我什么是问题我是如此迷失
Environment:
Request Method: GET
Request URL: http://mywesbite.genericdomain.co.uk/admin/shop/passwordresetrequest/4/
Django Version: 1.1.1
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'mywebsite.news',
'mywebsite.store_locator',
'mywebsite.css_switch',
'mywebsite.professional',
'mywebsite.contact',
'mywebsite.shop',
'tinymce',
'captcha']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware')
Template error:
In template /usr/lib/python2.5/site-packages/django/contrib/admin/templates/admin/change_form.html, error at line 20
Caught an exception while rendering: 'PasswordResetRequest' object has no attribute 'date'
10 :
11 : {% block coltype %}{% if ordered_objects %}colMS{% else %}colM{% endif %}{% endblock %}
12 :
13 : {% block bodyclass %}{{ opts.app_label …Run Code Online (Sandbox Code Playgroud) 我有一个小的自定义缩略图库.点击缩略图我想获得更大版本的图像.要做到这一点,我得到img的src.有了这个我想用另一个字符串替换字符串的某个部分.例如,缩略图的源可能如下所示:
/media/uploads/headshots/width_60_259850_10150280251835435_717615434_9570015_4084479_n.jpg
Run Code Online (Sandbox Code Playgroud)
我需要更换width_60_用width_104_.这可能与Javascript?
我有以下代码,
$(".delete.red").live("click", function () {
var self = $(this);
var loadUrl = $(this).attr('href');
alert("clicked");
//var interestParents = self.parents('div:eq(4)').attr("id");
$.ajax({
type: "POST",
url: loadUrl,
dataType: "json"
}).success(function (msg) {
alert(msg);
self.parent().parent().parent().parent().parent().parent().remove();
$(".selected strong").text(msg.icount)
});
return false;
});
Run Code Online (Sandbox Code Playgroud)
这个代码在点击它向请点击的链接href发送请求的链接时做了什么,它应该找到该链接的最外层父节点并从标记中删除它自己.
但是请求没有得到done()我现在得到的功能反馈它几乎就好像它没有被调用,这看起来很奇怪,因为当我查看网络选项卡时,我可以看到链接href已被访问,我可以看到200 OK回应.
Waht正在进行中?
django ×5
python ×5
javascript ×3
jquery ×3
ajax ×2
php ×2
string ×2
codeigniter ×1
django-views ×1
mysql ×1
regex ×1
sql ×1
stack-trace ×1