Django 1.7过滤器水平不适用于foreignkey

时间:2015-11-12 08:29:03

标签: python django

我有一个节目模型,我想在电影和场地字段中添加水平过滤器。

class Show(models.Model):

    MOVIE_TYPES = (
        ('2', '2D'),
        ('3', '3D'),
    )

    CINEMAS = (
        ('C1', 'Cinema 1'),
        ('C2', 'Cinema 2'),
        ('C3', 'Cinema 3'),
        ('C4', 'Cinema 4'),
    )

    movie = models.ForeignKey('Movie', related_name='shows')
    venue = models.ForeignKey(Venue)
    old_details = models.TextField(blank=True, editable=False,)
    starts = models.DateField(db_index=True,)
    starts_time = models.TimeField(db_index=True,)
    couple_price = models.IntegerField(blank=True, null=True)
    vip = models.IntegerField(blank=True, null=True)
    cinema = models.CharField(
        max_length=10,
        choices=CINEMAS,
        blank=True,
        null=True
    )
    comment = models.TextField(blank=True, )
    booking_url = models.URLField(blank=True, )
    created = models.DateTimeField(editable=False, db_index=True,)
    modified = models.DateTimeField(editable=False, db_index=True,)
    price = models.IntegerField(blank=True, null=True)
    new_price = models.IntegerField(blank=True, null=True)
    movie_type = models.CharField(
        max_length=1,
        choices=MOVIE_TYPES,
        blank=True,
        null=True
    )

在管理员中我已经设置了这样但是当我运行python2.7 manage.py migrate movies并重新启动服务器时,它仍然显示为下拉列表。

class ShowAdmin(admin.ModelAdmin):
    list_display = ['movie','venue','starts', 'starts_time','active']
    search_fields = ['movie__name','venue__name' ]
    list_filter = ['venue', 'created']
    filter_horizontal = ('venue','movie') 

更新

我将list_filter编辑为list_filter = ['created']进行迁移并重新启动服务器并且更改生效我不认为这是迁移问题。注意:我也从Django 1.5升级到1.7。

1 个答案:

答案 0 :(得分:1)

filter_horizontalfilter_vertical选项适用于多对多字段。你不能将它们用作外键。

选项的docs仅提及多个字段,如果您look at the code,则可以看到窗口小部件仅用于多对多表单字段。