0

我在模型中使用 django 1.6 和泛型关系。我对aggregate模型中的功能有疑问:

以下是我的部分观点:

class EventListView(PageContextMixin, ListView):
    model = Activity
    template_name = 'events/eventlist.html'

    def get_queryset(self):
        seasons = Season.objects.all()
        if not self.request.user.is_superuser:
            seasons = seasons.filter(is_active=True)
            active_seasons_ids = list(IsActiveFlag.objects.exclude(is_active=False).values_list('id', flat=True))
            seasons = list(Season.objects.filter(isactiveflags__id__in=active_seasons_ids))
        minmax = seasons.aggregate(Min('start'), Max('end'))
        min_date = minmax['start__min']
        max_date = minmax['end__max']

        active_sale_and_cycles_ids = list(SaleAndCycle.objects.exclude(is_sale_active=False).values_list('id', flat=True))
        filters_sale = Q(sale_and_cycles__id__in=active_sale_and_cycles_ids)
        active_is_cyclic_event_ids = list(SaleAndCycle.objects.exclude(is_cyclic_event_active=False).values_list('id', flat=True))
        filters_cycle = Q(sale_and_cycles__id__in=active_is_cyclic_event_ids)
        sales_events_activities = Activity.objects.filter(Q(filters_sale, online=True) | Q(filters_cycle, online=True))   
        sales_events_ids = sales_events_activities.values_list('id', flat=True)
        minmax_sales_events_activities = sales_events_activities.aggregate(Min('start'), Max('end'))
        max_date_sales_events_activities = minmax_sales_events_activities['end__max']

我在这个地方得到一个错误:

minmax_sales_events_activities = sales_events_activities.aggregate(Min('start'), Max('end'))

错误:

no such table: events_saleandcycle

但是数据库中有一个表(我使用 sqlite),其中包含字段:id、content_type_id、object_id、position、is_sale_active、is_cyclic_event_active、cycle_link

class SaleAndCycle(SortableVAExtra):
    is_sale_active = models.BooleanField(default=False)
    is_cyclic_event_active = models.BooleanField(default=False)
    cycle_link = models.CharField(max_length=255, null=True, blank=True)

    def __unicode__(self):
        return str(self.is_sale_active)
4

1 回答 1

1

有一个针对 Django 1.6 的已解决问题描述了注释(聚合)的失败。与修复相关的提交仅存在于 Django 1.7a 及更高版本中。

我担心你唯一的机会是升级到 Django 1.7。

于 2017-03-06T12:22:43.307 回答