[Answer]-Django 1.6 models.Manager Complaining about to many values to unpack

1πŸ‘

βœ…

I think it’s because kwargs["field"] is just a string. Try

def date_search_threads(self, date1, date2, **kwargs):
    print kwargs["field"]
    date1 = datetime.datetime.strptime(date1, "%m-%d-%Y").date()
    date2 = datetime.datetime.strptime(date2, "%m-%d-%Y").date()
    date2 = date2 + datetime.timedelta(days=1)

    param_filter = {'{}__range'.format(kwargs["column"]): (date1, date2)}
    if 'field' in kwargs:
        field = kwargs['field'].split('=')  
        param_filter[field[0]] = field[1]
    return super(ListAllObjectsManager, self).get_queryset().filter(**param_filter))

Or better, directly pass a dict in kwargs:

...
context['unanswered_threads'] = ThreadVault.list_all_threads \
        .date_search_threads(date1, date2, field={'unanswered': True},
        column="latest_post_date").count()

And

...
param_filter = {'{}__range'.format(kwargs["column"]): (date1, date2)}
param_filter.update(kwargs.get('field', {})
return super(ListAllObjectsManager, self).get_queryset().filter(**param_filter))
πŸ‘€Seb D.

Leave a comment