我可以帮您翻译,以下是翻译结果:
现在,在我的看法中,我已经为两个模型创建了对象:
我想在
我有两个模型,我想根据它们的ID找出共同的值集合
第一个模型:
from __future__ import unicode_literals
from django.db import models
from django.contrib.auth.models import User
# WE ARE AT MODELS/UNIVERSITIES
class Universities(models.Model):
id = models.IntegerField(db_column="id", max_length=11, help_text="")
name = models.CharField(db_column="name", max_length=255, help_text="")
abbreviation = models.CharField(db_column="abbreviation", max_length=255, help_text="")
address = models.CharField(db_column="address", max_length=255, help_text="")
status = models.BooleanField(db_column="status", default=False, help_text="")
createdAt = models.DateTimeField(db_column='createdAt', auto_now=True, help_text="")
modifiedAt = models.DateTimeField(db_column='modifiedAt', auto_now=True, help_text="")
updatedBy = models.ForeignKey(User,db_column="updatedBy",help_text="Logged in user updated by ......")
class Meta:
managed = False
get_latest_by = 'createdAt'
db_table = 'universities'
另一个模型:
from __future__ import unicode_literals
from django.db import models
class NewsUniversityMappings(models.Model):
id = models.IntegerField(db_column="id", max_length=11, help_text="")
newsMappingId = models.IntegerField( db_column='newsMappingId' ,max_length=11, help_text="")
universityId = models.IntegerField( db_column='universityId', max_length=11, help_text="")
createdAt = models.DateTimeField(db_column='createdAt', auto_now=True, help_text="")
class Meta:
managed = False
db_table = 'news_university_mappings'
现在,在我的看法中,我已经为两个模型创建了对象:
def add_promoter_news(request, mapping_id=None, news_virtual_id=None):
try:
university_all_list = Universities.objects.using("cms").all
published_university_list = NewsUniversityMappings.objects.using("cms").filter(newsMappingId=news_virtual_id).all()
我想在
Universities
模型的in
基础上,与NewsUniversityMappings
模型的universityId
找到两个模型共同的部分。非常感谢您提供的任何帮助。谢谢。
university_all_list = Universities.objects.using("cms").all()
中忘记了括号,当然函数all
没有 'filter'。请尝试修改后的答案。 - undefined