我有两个模型。他们中的一个-事件,另一个-专家,谁领导了这个事件。
事件模型
from django.db import models
# Create your models here.
class Article(models.Model):
class Meta():
db_table = 'article'
article_title = models.CharField(max_length=200)
article_anchor = models.CharField(max_length=200)
article_text = models.TextField()
article_date = models.DateTimeField()专家模型
from django.db import models
# Create your models here.
class Expert(models.Model):
class Meta():
db_table = 'expert'
expert_name = models.CharField(max_length=200)
expert_anchor = models.CharField(max_length=200)
expert_discr = models.TextField()我需要向我的事件模型添加某种类型的Choise Field,我可以在其中按名称选择专家(expert_name)。
此外,在此之后,当我打开带有事件模型的页面时,我希望看到所有事件模型字段和所有专家模型字段一起……
所以,主要的问题是,我如何在另一个模型中获得带有专家模块字段的选择列表?
发布于 2015-04-09 01:35:02
您可以添加一个字段,以此为文章模型my_expert=models.ForeignKey(Expert,verbose_name="expert"),然后,如果您将通过管理员或表单查看此模型,将有链接到专家的这篇文章的选择下拉列表。
发布于 2015-04-09 01:35:27
你正在寻找一个外键。这是他们的docs。
https://stackoverflow.com/questions/29521390
复制相似问题