cheers again for the response. However the code i used to get the wrapper working is given below
def searchwrap(request): error = False if 'q' in request.GET: q = request.GET['q'] if not q: error = True else: articles = Mymodel.objects.filter(title__icontains=q) return django.views.generic.date_based.archive_index( request, queryset = set, template_name = 'search_results.html', extra_context = {'set': set} ) return date_based.archive_index( request, Mymodel.objects.filter(status=1), 'pub_date', template_name = 'search_form.html', extra_context = { 'error': error, } ) great! So, in order to get a (very simple) search box on each page in a default blog app with url which goes like /year/month/day/slug/ i wrapped archive_index, archive_year, archive_month, archive_day and object_detail from django.views.generic import date_based with a function that picks up the from GET. This is obviously a very thick way of achieving this. In the interests of elegant code could i pass the relevant generic function view name to my wrapper? I tried this by just including a parameter in the call for the wrapper view but it didn't work, i thought something like this would suffice, but no: (r'^$',views.searchwrap(generic.view)), am i way off? Cheers, On Apr 20, 5:50 am, Anatoliy <anatoliy.la...@gmail.com> wrote: > Try this: > > return date_based.archive_index( > request, > Mymodel.objects.filter(status=1), > 'date_field': 'pub_date', > template_name = 'search_form.html', > extra_context = { > 'error': error, > } > ) > > On 20 апр, 02:01,SoCow<vivid.des...@gmail.com> wrote: > > > ok, i'm getting there. i figured out that i need to wrap the generic > > view in my own function. To make the problem clear i'm trying to get a > > simple search to live in the base.html template of a blog which uses > > the date_based generic view. My wrapper function consists of: > > > def searchwrap(request): > > error = False > > if 'q' in request.GET: > > q = request.GET['q'] > > if not q: > > error = True > > else: > > set= Mymodel.objects.filter(title__icontains=q) > > return django.views.generic.date_based.archive_index( > > request, > > queryset = set, > > template_name = 'search_results.html', > > extra_context = {'set': set} > > ) > > > return date_based.archive_index( > > request, > > template_name = 'search_form.html', > > extra_context = { > > 'error': error, > > 'queryset': Mymodel.objects.filter(status=1), > > 'date_field': 'pub_date' > > } > > ) > > > I'm now getting the error: > > > archive_index() takes at least 3 non-keyword arguments (1 given) > > > i thought that i was passing it 3 non-keyword arguments, no? > > > anyone any experience with this? > > > Thanks > > > On 19 Apr, 19:02,SoCow<vivid.des...@gmail.com> wrote: > > > > Hi all, > > > thanks for reading. > > > > I've implemented search for my site following the example in > > > thehttp://www.djangobook.com/en/2.0/chapter07/. My search view receives > > > the search term from a GET event. > > > > I want to use this same method in a generic view, but don't know how > > > Any ideas? > > > > Many thanks --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---