On Nov 24, 11:59 am, dash86no <[EMAIL PROTECTED]> wrote:
> I've implemented a search function which brings up a list of database
> items on a page. My template looks like this:
>
> {% extends "base.html" %}
>
> {% block content %}
>
>     {% if results %}
>       <ul>
>       {% for quote in results %}
>         <li>{{ quote|escape }}</l1>
>       {% endfor %}
>       </ul>
>     {% else %}
>       <p>No quotes found</p>
>     {% endif %}
> {% endblock %}
>
> My search code is like this:
>
> def search(request):
>     query = request.GET.get('q', '')
>     if query:
>         qset = (
>             Q(name__icontains=query) |
>             Q(company__name__icontains=query) |
>             Q(note__icontains=query)
>
>         )
>         #results = Quote.objects.filter(qset).distinct()
>         results = Quote.objects.filter(qset)
>     else:
>         results = []
>
>     return render_to_response("sam_app/search.html", {
>         "results": results,
>         "query": query
>     })
>
> The problem, is that the outputted list is just static text. What I
> want, is a series of links that when I click one one of them, will
> bring up the relevant item in a form for editing.
>
> I found 
> this:http://docs.djangoproject.com/en/dev/topics/forms/#topics-forms-index
>
> And saw the form.as_p form.as_table form.as_ul and got exited because
> I thought this might work. I edited the above code to make the search
> function pass a form object to the template, but then I got the error:
> Caught an exception while rendering: too many values to unpack.
>
> So I guess this isn't it?
>
> I know I could just put together a loop to generate links with the pk
> encoded inside the url, and do it like that, but it seems to me there
> should be a neat little method in django to do this automatically. It
> also though generic views might be the answer but I don't think you
> can customize those, right?
>
> Cheers,

You can use the create/update generic views[1] to provide the actual
edit pages. Once they are linked in your urls.py, you can use the {%
url %} tag[2] to link to them from your list template.

[1]: 
http://docs.djangoproject.com/en/dev/ref/generic-views/#create-update-delete-generic-views
[2]: http://docs.djangoproject.com/en/dev/ref/templates/builtins/#url

--
DR.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to