django懒得拿不工作?

时间:2017-06-14 09:42:30

标签: django django-models

我有3个模型新闻映射,新闻喜欢和新闻戳,如下所述:

from __future__ import unicode_literals

from django.db import models

from cms.models.boards import Boards
from cms.models.news import News

# WE ARE AT MODELS/NEWS MAPPINGS


class NewsMappings(models.Model):
    id = models.IntegerField(db_column="id", max_length=11, help_text="")
    newsId = models.ForeignKey(News, db_column='newsId', max_length=11, help_text="") 
    boardId = models.ForeignKey(Boards, db_column='boardId', max_length=11, help_text="") 
    isWallPost = models.BooleanField(db_column="isWallPost", default=False, help_text="")
    masterPostTypeId = models.IntegerField(db_column="masterPostTypeId",max_length=11,help_text="")

    class Meta:
        managed = False
        db_table = 'news_mappings'



from __future__ import unicode_literals
from django.db import models
from cms.models.appUsers import Users
from cms.models.newsMappings import NewsMappings


class NewsLikes(models.Model):
    id = models.IntegerField(db_column="id", max_length=11, help_text="")
    userId = models.ForeignKey(Users, db_column='userId', max_length=11, help_text="")
    newsId = models.ForeignKey(NewsMappings, db_column='newsMappingId', max_length=11, help_text="")
    createdAt = models.DateTimeField(db_column='createdAt', auto_now=True, help_text="")

    class Meta:
        managed = False
        db_table = 'news_likes'



from __future__ import unicode_literals

from django.db import models
from cms.models.appUsers import Users
from cms.models.newsMappings import NewsMappings
from cms.models.masterPokes import MasterPokes


class NewsPokes(models.Model):
    id = models.IntegerField(db_column="id", max_length=11, help_text="")
    userId = models.ForeignKey(Users, db_column='userId', max_length=11)
    newsMappingId = models.ForeignKey(NewsMappings, db_column='newsMappingId', max_length=11)
    masterPokeId = models.ForeignKey(MasterPokes, db_column='masterPokeId', max_length=11)
    otherPoke = models.CharField(db_column='otherPoke', max_length=255)
    createdAt = models.DateTimeField(db_column='createdAt', auto_now=True, help_text="")

    class Meta:
        managed = False
        db_table = 'news_pokes'

在我的模板中,我正在传递NewsMapping个对象。 我正在使用

newsMapping = NewsMappings.objects.all()

并将conteM中的newsMapping作为datalist传递。并将onloop on templated为{% for item in datalist%}

{{item.newslikes_set.all.count}}它给了我与新闻相关的数量,但当我将{{item.newspokes_set.all.count}}应用于新闻时,它不起作用。它总是给0。

0 个答案:

没有答案