我有一个django项目,其中有两个不同的应用程序。有一个用户和广告系列应用。我正在使用广告系列模型,并且想导入用户模型以作为外键链接。我可以成功地将市场活动模型导入用户模型并将其设置为前键。我不能反过来做。我将在下面附加一些代码。
IMPORT STATEMENTS-广告系列模型python文件:
from django.db import models
from users.models import Founder
from .choices import CATEGORY_CHOICES, PLATFORM_CHOICES, PROGRESS_CHOICES, SIZE_CHOICES
需要访问要导入的用户模型的露营模型:
class Update(models.Model):
campaign = models.ForeignKey(Detail, on_delete=models.CASCADE)
message = models.TextField()
impact = models.TextField()
founder = models.ForeignKey(Founder, on_delete=models.CASCADE)
def __str__(self):
return self.campaign.name + ' update'
这是我要导入的模型:
class Founder(models.Model):
user = models.ForeignKey(Credential, on_delete=models.CASCADE)
campaign = models.ForeignKey(Detail, on_delete=models.CASCADE)
company = models.CharField(max_length=50)
position = models.CharField(max_length=30)
commitment = models.TextField(null=True)
since_month = models.CharField(max_length=15, choices=MONTH_CHOICES)
since_year = models.IntegerField()
portfolio = models.CharField(max_length=200)
relation = models.TextField()
known = models.IntegerField()
verified = models.BooleanField(default=False)
def __str__(self):
return self.user.username + '-' + self.campaign.name
这是我现在已设置的文件结构。