sei-ec-remote / team-project-issues

0 stars 0 forks source link

associate many to many relationship with a dropdown list #170

Closed jadewang425 closed 1 year ago

jadewang425 commented 1 year ago

Describe the bug A clear and concise description of what the bug is. I created a form with a drop down list to associate exercises with a workout, but I'm not quite sure how to

What is the problem you are trying to solve? associate exercise(s) to workout

Expected behavior A clear and concise description of what you expected to happen. select the exercise(s) from the drop down list, and add to the workout

What is the actual behavior? A clear and concise description of what actually happened. getting an error page and exercise(s) not added

Post any code you think might be relevant (one fenced block per file)

    <div class="col s6">
        <form action="{% url 'add_exercise' workout.id exercise.id %}" method="POST">
            {% csrf_token %}
            <select name="" id="id_exercises"></select>
            {% for exercise in exercises %}
                {{ exercise }}
            {% endfor %}
            <input type="submit" class="btn" value="Add Exercise">
        </form>
    </div>

What is your best guess as to the source of the problem? in the function in views or in the html file

What things have you already tried to solve the problem? different functions or looping over the exercises available

Additional context Add any other context about the problem here.

Paste a link to your repository here https://github.com/jadewang425/gym_grid

asands94 commented 1 year ago

What is the error?

jadewang425 commented 1 year ago

I'm not sure what I did but I can't see any options from the dropdown list anymore... image

jadewang425 commented 1 year ago

I got it back! here's the message image

asands94 commented 1 year ago

Can you also share the view.py thats responsible for adding an exercise. Did you add the exercise_id in the form.is_valid() section?

jadewang425 commented 1 year ago

I'm not sure if using the form is the best way to go, but when I tried with the associate function similar to associating toy to a cat, it doesn't let me iterate the exercises for the dropdown list image

asands94 commented 1 year ago

If you print exercise_id are you getting a number back?

jadewang425 commented 1 year ago

No, I'm not getting the number back and it doesn't print in the terminal as well. image

asands94 commented 1 year ago

Ok, then you may want to try adding in a bunch of exercises then associating them like we did with cats and toys using the assoc_toys method