Good day, Currently i m working on a project, it is my first time doing such. I'm on the back end and do some stuff on the front end to make it more intuitive. I chose django because its straightforward, but i'm having some difficulty creating an advanced search. Here is the problem:
First i made 2 scrips to import full texts to a table on postgresql. Lets call this table trt_text(in this this table there are 2 texts each It has the title and content. Then i did another script to put another .txt on postgresql. Lets call this table trt_keyconcepts. This table has 3 "columns" the first one contains a word/sentence from the trt_text, the second one contains what type of word/sentence it is, and the third column is integer, it contains the number that said word appears on the text.
Using ChatGPT these views were made:
views.py:
def advanced_search(request):
return render(request, "app/advanced_search.html")
def advanced_search_results(request):
if request.method == "GET":
entity_name = request.GET.get("entity_name", "")
entity_type = request.GET.get("entity_type", "")
frequency = request.GET.get("frequency", "")
search_results = Text.objects.all()
if entity_name:
search_results = search_results.filter(content__icontains=entity_name)
if entity_type:
search_results = search_results.filter(textfile__name=entity_name)
if frequency:
search_results = search_results.filter(textfile__frequency=int(frequency))
return render(
request, "app/advanced_search_results.html", {"search_results": search_results}
)
return redirect("advanced_search")
At this point i didn t create a relation between the table that contains the keyconcepts and the table that contains the full texts.
I m having diffuculty to do this.
Here is urls.py:
path('advanced_search/', advanced_search, name='advanced_search'),
path('advanced_search/results/', advanced_search_results, name='advanced_search_results'),
]
I also have the html templates but i m not succeeding can someone help me?
I expected to create a functional logic, but clearly i m doing it wrongly.
The objective to associate the first colmun of trt_concepts with the trt_text to see where those words are on the text and display it on the search results. Then there is an option to sort them on front end and using the 2 column of trt_keyconcepts
Can someone help me? Should i create an advanced_search on forms.py?
@Pycm I have deleted the templates to redo it.
But i m trying to use the first column of trt_keyconcepts to filter what is on trt_text. What can i do on django to achieve this view?
You can use
Django Q