0

I have a Django project where I am pulling back a list of tasks. These tasks could be for many projects.

Task1: Project1 Task2: Project2

I really want to be able to group by project, so they all sit together, but the project names are input by the user, so I can't hardcode if statements.

How could I approach this?

kikee1222
  • 1,866
  • 2
  • 23
  • 46

1 Answers1

0

You should not hardcode, period.
You really should work on your question skills. Based on the little information you gave, Your problem might be one of the following.
You need to search in your database based on the project name that the user has searched for. You have a few ways to approach this, based on your javascript abilities (in no particular order):

  1. Give the user a list of cards, each of which represents a single project. Once the user clicks on the card, you get the project id, send it to the server and fetch it from the database. You might need to look into frameworks such as React, or Vue for this task even though you can achieve the same with vanilla JS.
  2. Create a simple text field, take the user input, query the input against your database and return the list of results, or tell the user that there is no project by the given name.
  3. Create an advanced text field where the list of projects are suggested based on the input of the user (somewhat like the Google search input)
  4. Create a select dropdown, populated with the names of projects, and allow/force users to select one.

OR, you just need to show all of your tasks but just nest the tasks in their parent projects. The simplest way to achieve this is explained here. The other way (the better way) to approach this is to serialize the projects and add the corresponding array of serialized tasks.

Ramtin
  • 3,058
  • 1
  • 22
  • 24