加入django模特

时间:2011-06-21 12:51:19

标签: django django-models join

我想在django中使用三个不同的模型将结果放在一个列表中。我如何应用三个模型的连接。

class CurrentDomainChecks(models.Model):

    domain = models.ForeignKey(Domains)
    check_type = models.ForeignKey(CheckType)
    check_date = models.DateTimeField(auto_now_add = True, primary_key=True)
    check_value = models.CharField(_('check value'), max_length = 2048)
    check_passed = models.BooleanField(default = False)

class DomainStatus(models.Model):

    domain = models.ForeignKey(Domains)
    domain_status_date = models.DateTimeField(auto_now_add=True,null = True, blank = True)
    domain_status = models.IntegerField(null = True, blank = True)

class Domains(models.Model):

    domain_name = models.CharField(_('domain name'), max_length = 255, unique = True)
    verified = models.BooleanField(default = False)
    user = models.ForeignKey(User)
    date_added = models.DateTimeField(auto_now_add=True,null = True, blank = True)
    date_last_changed = models.DateTimeField(auto_now=True,null = True, blank = True)
    monitoring_frequency = models.CharField(_('monitoring frequency'), max_length = 20,blank = True,null = True)

    def __unicode__(self):
        return self.domain_name 

2 个答案:

答案 0 :(得分:3)

您是否阅读过有关JOIN的内容?

Django: implementing JOIN using Django ORM?

答案 1 :(得分:2)