2017-02-22 92 views
0

我想實現我的項目django-filters,但我已經打了一個路障:/不知何故filter instance正從上下文中刪除..CBV覆蓋Django的過濾器方面

class ListReservations(LoginRequiredMixin, FilterView): 
    template_name = 'reservations/homepage.html' 
    paginate_by = 25 
    model = Reservation 
    filterset_class = ReservationFilter 

    def get_context_data(self, **kwargs): 
     ctx = super(ListReservations, self).get_context_data() 
     ctx['today'] = datetime.datetime.now().strftime('%d/%m') 
     return ctx 

結果仍然得到過濾,但沒有獲得{{filter.form}}

回答

0

得到它通過執行以下工作:

def get_context_data(self, **kwargs): 
    ctx = super(ListReservations, self).get_context_data() 
    ctx['today'] = datetime.datetime.now().strftime('%d/%m') 
    ctx['filter'] = self.get_filterset(self.get_filterset_class()) 
    return ctx 

希望它可以幫助別人一天:)

0

超級呼籲get_context_data應包括kwargs:

ctx = super(ListReservations, self).get_context_data(**kwargs)