我有一个大学名单,我想用新闻ID存储。 我的模型是这样的: -
from __future__ import unicode_literals
from django.db import models
from cms.models.universities import Universities
from cms.models.newsMappings import NewsMappings
class NewsUniversityMappings(models.Model):
id = models.IntegerField(db_column="id", max_length=11, help_text="")
newsMappingId = models.ForeignKey(NewsMappings, db_column='newsMappingId' ,max_length=11, help_text="")
universityId = models.ForeignKey(Universities, 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'
我的观点是: -
if request.method =='POST':
university = request.POST.getlist('universityId')
newsId = 1;
add_news_university_mappings = NewsUniversityMappings(universityId=university, newsMappingId=newsId)
add_news_university_mappings.save(using="cms")
messages.success(request, 'Successfully added to the university list')
现在,如何在数据库中再次保存大学列表中的newsid值。