1

我对 django 查询有疑问。我是新的 Django 程序员。

我有三个模型:

class Device(models.Model):
    class Meta:
         ordering = ('dev',)
         verbose_name = _(u'Interface')

    dev = models.CharField(_(u'Interface'), max_length=5, editable=True,
          unique=True)
    enable = models.BooleanField(_(u'Enabled'), default=True)
    dhcp = models.BooleanField(_(u'DHCP'), default=False,

第二个模型:

class Config(models.Model):
    class Meta:
       ordering = ('ip_address',)
       verbose_name = _(u'Network Configuration')
       verbose_name_plural = _(u'Network Configurations')

   device = models.ForeignKey(Device)
   ip_address = models.IPAddressField(_(u'IP Address'), unique=True)
   netmask = NetmaskAddressField(_(u'Netmask'))
   description = models.CharField(_(u'Description'), blank=True, null=True,
       max_length=255)

第三个模型:

 class Dhcp(models.Model):

    class Meta:
       ordering = ('gateway',)
       verbose_name = _(u'DHCP Configuration')
       verbose_name_plural = _(u'DHCP Configurations')

   config = models.ForeignKey(Config)
   gateway = models.IPAddressField(_(u'Gateway'), null=True)
   dns_primary = models.IPAddressField(_(u'DNS Primary'), null=True)
   dns_second = models.IPAddressField(_(u'DNS Second'), blank=True)
   leases_time = models.IntegerField()
   nat = models.IPAddressField(_(u'NAT'), blank=True)
   max_time = models.IntegerField()

现在,我的问题是:如何显示没有 Dhcp 配置的设备列表?

例如:我有Device其中具有三种配置。我需要检查所有配置Device以确保没有 DHCP 配置,最后显示设备,但我不知道该怎么做。

4

1 回答 1

-1
Device.objects.filter(config__dhcp__isnull=True)

更多关于这里的查询

于 2013-02-21T20:26:55.180 回答