Django截断了不正确的DOUBLE值:

时间:2014-01-02 05:11:34

标签: django django-queryset

我正在尝试拉出用户的组织,并在上下文处理器上提供一个查询集,该处理器将根据菜单选择通过多个不同的过滤器进行过滤。我得到的当前错误标题为:Truncated incorrect DOUBLE value:(后面是所有组织数据库之一的org_name)。在创建新闻文章并附加组织之前,我没有任何问题。

组织模型:

class Organizations(models.Model):
org_name = models.CharField(max_length=200)
org_admin = models.ForeignKey(User) #Defines the admin user account for editing
org_description = models.CharField(max_length=1000)
org_phone = models.CharField(max_length=10)
org_county = models.ForeignKey(County)
org_address = models.CharField(max_length=200, blank=True)
org_address2 = models.CharField(max_length=200, blank=True)
org_city = models.CharField(max_length=200, blank=True)
org_zip = models.CharField(max_length=10, blank=True)
org_type = models.ForeignKey(OrgType, blank=True)
sub_org = models.ForeignKey('self', null=True, blank=True) # defines a heirarchy of organiztions
org_logo = models.ImageField(upload_to = 'pic_folder/', blank=True)
org_web = models.CharField(max_length=500, blank=True)
org_facebook = models.CharField(max_length=200, blank=True)
org_twitter = models.CharField(max_length=200, blank=True)
def __unicode__(self):
    return self.org_name

新闻模式:

class News(models.Model):
title   = models.CharField(max_length=200)
author = models.ForeignKey(User)
slug = models.SlugField(unique=True)
content = models.TextField()
date = models.DateTimeField(default=datetime.now)
category    = models.CharField(max_length=1, choices=NEWS_CATEGORIES, blank=True)
news_orgs = models.ManyToManyField(Organizations, blank=True)
news_county = models.ManyToManyField(County, blank=False)

def __unicode__(self):
    return self.title

UserOrgConnections模型:

class UserOrgConnections(models.Model):
user = models.ForeignKey(User)
orgs = models.ManyToManyField(Organizations)

上下文处理器:

def mynews(request):
now = datetime.now()    
if request.user.is_authenticated(): 
    user = request.user.get_profile()   

    userorgs = UserOrgConnections.objects.filter(user = user)
    print userorgs.values('orgs')

    county = user.county.all()      

MyNews = News.objects.filter(news_orgs__org_name=userorgs)  

promotions = OrgPromotion.objects.filter(organization__org_county=county)
dailyspecials = OrgDailySpecials.objects.filter(organization__org_county=county)        
newsall = MyNews.all().order_by('-date') 
entnews = MyNews.filter(news_county=county, category='E')   
technews = MyNews.filter(news_county=county, category='T')
healthnews = MyNews.filter(news_county=county, category='H')
livingnews = MyNews.filter(news_county=county, category='L')
humornews = MyNews.filter(news_county=county, category='H')
travelnews = MyNews.filter(news_county=county, category='R')
moneynews = MyNews.filter(news_county=county, category='M')
return {
'newsall': newsall, 
'now': now, 
'entnews': entnews, 
'technews': technews, 
'livingnews': livingnews, 
'humornews': humornews, 
'travelnews': travelnews, 
'moneynews': moneynews,
}

模板代码段

{% for newsall in newsall %}
    {% if newsall.date >= now %} 
            {{ newsall }}
            {{newsall.date }}

    {% endif %}
{% endfor %}

1 个答案:

答案 0 :(得分:0)

以下代码序列看起来很可疑:

userorgs = UserOrgConnections.objects.filter(user = user)
MyNews = News.objects.filter(news_orgs__org_name=userorgs)

这实际上要求Newsnews_orgs.org_name个对象的序列,其UserOrgConnections值等于userorgs列表。您尚未列出{{1}}的模型,因此无法使用所提供的信息确定解决方案。

也许您应该查看能够执行在列表上过滤的查询的Django Queryset in operator