Ticket #9222: callable_queryset.diff

File callable_queryset.diff, 3.4 KB (added by raffaele.salmaso@…, 7 years ago)
  • django/views/generic/date_based.py

    diff -rNu django-1/django/views/generic/date_based.py django-2/django/views/generic/date_based.py
    old new  
    2222            Latest N (defaults to 15) objects by date
    2323    """
    2424    if extra_context is None: extra_context = {}
     25    if callable(queryset):
     26        queryset = queryset()
    2527    model = queryset.model
    2628    if not allow_future:
    2729        queryset = queryset.filter(**{'%s__lte' % date_field: datetime.datetime.now()})
     
    6668            (Only available if make_object_list argument is True)
    6769    """
    6870    if extra_context is None: extra_context = {}
     71    if callable(queryset):
     72        queryset = queryset()
    6973    model = queryset.model
    7074    now = datetime.datetime.now()
    7175
     
    120124    except ValueError:
    121125        raise Http404
    122126
     127    if callable(queryset):
     128        queryset = queryset()
    123129    model = queryset.model
    124130    now = datetime.datetime.now()
    125131
     
    185191    except ValueError:
    186192        raise Http404
    187193
     194    if callable(queryset):
     195        queryset = queryset()
    188196    model = queryset.model
    189197    now = datetime.datetime.now()
    190198
     
    241249    except ValueError:
    242250        raise Http404
    243251
     252    if callable(queryset):
     253        queryset = queryset()
    244254    model = queryset.model
    245255    now = datetime.datetime.now()
    246256
     
    311321    except ValueError:
    312322        raise Http404
    313323
     324    if callable(queryset):
     325        queryset = queryset()
    314326    model = queryset.model
    315327    now = datetime.datetime.now()
    316328
  • django/views/generic/list_detail.py

    diff -rNu django-1/django/views/generic/list_detail.py django-2/django/views/generic/list_detail.py
    old new  
    4343            A list of the page numbers (1-indexed).
    4444    """
    4545    if extra_context is None: extra_context = {}
    46     queryset = queryset._clone()
     46    if callable(queryset):
     47        queryset = queryset()
     48    else:
     49        queryset = queryset._clone()
    4750    if paginate_by:
    4851        paginator = Paginator(queryset, paginate_by, allow_empty_first_page=allow_empty)
    4952        if not page:
     
    115118    """
    116119    if extra_context is None: extra_context = {}
    117120    model = queryset.model
     121    if callable(queryset):
     122        queryset = queryset()
    118123    if object_id:
    119124        queryset = queryset.filter(pk=object_id)
    120125    elif slug and slug_field:
  • docs/ref/generic-views.txt

    diff -rNu django-1/docs/ref/generic-views.txt django-2/docs/ref/generic-views.txt
    old new  
    5757``year``, etc. do above) or from the additional-information dictionary (as for
    5858``queryset``, ``date_field``, etc.).
    5959
    60 Most generic views require the ``queryset`` key, which is a ``QuerySet``
    61 instance; see :ref:`topics-db-queries` for more information about ``QuerySet``
    62 objects.
     60Most generic views require the ``queryset`` key, which can be either a ``QuerySet``
     61instance  or a callable object which returns a ``QuerySet``; see
     62:ref:`topics-db-queries` for more information about ``QuerySet`` objects.
    6363
    6464Most views also take an optional ``extra_context`` dictionary that you can use
    6565to pass any auxiliary information you wish to the view. The values in the
Back to Top