2009-07-24 178 views
0

我正在使用一个对象的多表继承,并且我需要将父对象外键引用的选择限制为仅应用子系统的规则。覆盖继承的行为

from schedule.models import Event, Rule 

class AirShowRule(Rule): 
    """ 
    Inheritance of the schedule.Rule 
    """ 
    rule_type = models.TextField(default='onAir') 

class AirShow(Event): 
    station = models.ForeignKey(Station) 
    image = models.ImageField(upload_to='images/airshow', null=True, blank= True) 
    thumb_image = models.ImageField(upload_to='images/airshow', null=True, blank= True) 

现在,在管理员中,我只希望AirShowRule(s)成为AirShow(Event)的选项。我得到的是schedule.event系统中的所有规则。

我从http://code.google.com/p/django-schedule/

回答

1

发现Django的时间表继承我看着列出的类的结构,你应该补充一点:

class AirShow(Event): 
    ... your stuff... 
    rule = models.ForeignKey(AirShowRule, null = True, blank = True, 
          verbose_name="VERBOSE NAME", help_text="HELP TEXT") 

应该得到的一切直(改为“规则”中的“AirShowRule”

您还应该确保实施AirShowRule更彻底,因为我想像你是不是覆盖rule_type,如果你是,我不认为它会做所有你想要

*参见:models.py:23

...这条线从models.py:103与参数的修改次数:verbose___name & help_text(可能是可选的,但我会留给你检查)

要知道,我以前没有使用这些模块,但是这应该给你推继续:)

+0

谢谢我正在研究这个解决方案。 – 2009-07-27 15:55:40