Django - How use generic views from a Django external App in my own App?

I'm new to Django...

I have installed a Django external App called Haystack, this external App have a "views.py" file inside "python2.6/site-packages/haystack". I think this "views.py" is called a "generic view" in Django terms.

This generic view is called using "urls.py" like this:

urlpatterns = patterns('haystack.views', 
                   url(r'^search/$', FacetedSearchView(form_class=FacetedSearchForm, searchqueryset=sqs), name='haystack_search'), 
)

I need to make the jump from this generic views to my App. My question goes in the direction of How Can I Do This?

The code of Haystack "views.py" goes like this:

from django.conf import settings
from django.core.paginator import Paginator, InvalidPage
from django.http import Http404
from django.shortcuts import render_to_response
from django.template import RequestContext
from haystack.forms import ModelSearchForm, FacetedSearchForm
from haystack.query import EmptySearchQuerySet


RESULTS_PER_PAGE = getattr(settings, 'HAYSTACK_SEARCH_RESULTS_PER_PAGE', 20)


class SearchView(object):
    ...

    def __init__(self, template=None, load_all=True, form_class=None, searchqueryset=None, context_class=RequestContext, results_per_page=None):
    ...

    def __call__(self, request):
    ...

    def build_form(self, form_kwargs=None):
    ...

    def get_query(self):
    ...

    def get_results(self):
    ...

    def build_page(self):
    ...

    def extra_context(self):
    ...

    def create_response(self):
    ...


def search_view_factory(view_class=SearchView, *args, **kwargs):
    ...


class FacetedSearchView(SearchView):
    ...

    def __init__(self, *args, **kwargs):
    ...

    def build_form(self, form_kwargs=None):
    ...

    def extra_context(self):
    ...


def basic_search(request, template='search/search.html', load_all=True, form_class=ModelSearchForm, searchqueryset=None, context_class=RequestContext, extra_context=None, results_per_page=None):
    ...

Can someone give what steps I should follow to take out the code from the "urls.py" and put the thing working in my "views.py" App?

Best Regards,

Answers


Try to put (r'^search/', include('haystack.urls')),. You also might want to read "Getting started with Haystack"

Try:

#your root urls.py
from django.conf.urls.defaults import *
from haystack.forms import FacetedSearchForm
from haystack.query import SearchQuerySet
from haystack.views import FacetedSearchView

sqs = SearchQuerySet().filter(author='john')

urlpatterns = patterns('haystack.views',
url(r'^/my_custom_very_special_url$', FacetedSearchView(
    template='my/special/path/to/faceted_search.html',
    searchqueryset=sqs,
    form_class=FacetedSearchForm
), name='haystack_search'),
)

BTW, it's all in the docs.


Did you follow all the steps in the docs?

Use the extra_context method to add or overwrite the other variables in the context.


Need Your Help

need some php function to remove slashes

php strip

My original string look like this .

Does it make sense to set up mediaPlayer to run in a separate thread in Android?

android multithreading media-player

I've recently begun experimenting with a mediaPlayer instance in my Android app. I implemented a couple different beeps for feedback to the user. Now, when I implemented an audioTrack (for a comp...