Cannot override search method of SearchForm class

7 views
Skip to first unread message

Francesco Lussignoli

unread,
Jul 6, 2025, 3:12:27 AMJul 6
to django-oscar

Hi everyone,

I’m using Oscar + Django and I have a functioning website.
I’m trying to override the SearhForm class by the usual steps (app forking) but seems that the ‘search’ method cannot be override from the child class…

Here the code in my custom app:

'''

from oscar.apps.search.forms import SearchForm as CoreSearchForm

class SearchForm(CoreSearchForm):

    def search(self):
        print(" --------- CHILD METHOD -----------")

'''

I’ve added to the original parent class (inside oscar.apps.search.forms) for the debug some prints like so:

'''

class SearchForm(FacetedSearchForm): ... def search(self): print(" --------- PARENT METHOD -----------") sqs = super(FacetedSearchForm, self).search() print("1. sqs: ", list([e['pk'] for e in sqs.values('pk')])) ... print("2. sqs: ", list([e['pk'] for e in sqs.values('pk')])) return sqs

'''

Here the output on terminal when I perform some product sorting:

'''

--------- PARENT METHOD -----------
haystack.forms - SearchForm: 'search()'
1. sqs:  ['10', '1', '4', '7']
2. sqs:  ['4', '1', '10', '7']
[05/Jul/2025 17:34:50] "GET /shop/catalogue/?q=&sort_by=price-asc HTTP/1.1" 200 65452

'''

So it seems the child method has not been called…

Anyone can understand what is happening?

Thank you in advance for any help!




Reply all
Reply to author
Forward
0 new messages