有没有办法过滤一些与django管理站点中的另一个模型无关的模型记录?

时间:2012-02-23 09:13:47

标签: django django-admin

class   Town        (models.Model):
    name        = models.CharField  (max_length     = 150,
                                     verbose_name   = _("Human settlement name"),
                                    )
    ref_town    = models.ForeignKey  ('self',
                                     blank          = True,
                                     null           = True,
                                     verbose_name   = _("Superior human settlement"),
                                     help_text      = _("Superior human settlement name (for subordinate settlements)"),
                                    )
class   CoalMine    (models.Model):
    name        = models.CharField  (max_length     = 150,
                                     verbose_name   = _("Coal mine"),
                                     help_text      = _("Coal mine name"))
    town        = models.ForeignKey (Town,
                                     default        = 1,
                                     verbose_name   = _("town"))

我的数据中有很多城镇,我需要过滤那些与煤矿无关的城镇。有没有解决方案?

1 个答案:

答案 0 :(得分:0)

从Django 1.3开始,你可以override SimpleListFilter让它做你想做的事。