Navigation

    ask avan logo
    • Register
    • Login
    • Search
    • Categories
    • Unsolved
    • Solved

    Python3/Django - Search Bar Query - Filter through Multiple Models(3) - Chain Results - Only displays results from one model.

    Python
    django filter python3 queries search bar
    2
    2
    28
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • N
      nub21 last edited by

      Beginner Coder here: Trying to practice building a search bar that will take the user's input and query the input through filters on multiple Models (3 of them). Results should chain together in a list and then return those results in a search page using a for in loop.

      Results of searching for data found in 1st Model: Works perfectly - all rows requested are returned.

      Results of searching for data found in 2nd Model: , , (literally commas)

      Results of searching for data found in 3rd Model: key returned followed by commas.

      Any help would be most appreciated.

      views.py

      views.py

      form on home page with search bar:

      home.html

      search_results.html:

      search page

      urls.py (works fine, but including anyway)

      urls.py

      Info re: 3 Models used - too big to display so just pasting Class with attributes for each model instance:

      class Team(models.Model):
      name = models.CharField(max_length=30)
      grade = models.IntegerField()
      gender = models.CharField(max_length=15)

      class Stat(models.Model):
      name = models.CharField(max_length=10)
      record = models.CharField(max_length=10)
      points = models.IntegerField()

      class Player(models.Model):
      first_name = models.CharField(max_length=20)
      number = models.IntegerField()
      position = models.CharField(max_length=2)

      Hope this is enough information to explain what I am not doing correctly.

      Reply Quote 1
        1 Reply Last reply

      • avan
        avan last edited by

        You are probably way past this but I would recommend printing out the whole object list before you print out team, player and stats. That way you can see if everything looks correct before printing formatted info. If the info is not correct go back and try to determine where it failed to load the data correctly. I would use print statements again for that.

        Reply Quote 0
          1 Reply Last reply

        • First post
          Last post