sei-ec-remote / project-4-issues

Open an issue to receive help on project 4
0 stars 0 forks source link

Using django messages. Having issue getting a message to come up when deleting an item #228

Closed tthephas closed 11 months ago

tthephas commented 1 year ago

What stack are you using?

(ex: MERN(mongoose + react), DR(django + react), PEN, etc.)

DR

What's the problem you're trying to solve?

trying to get a message to come up when deleting an item.

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

@login_required
def delete_chore(request, kid_id, chore_id):
  # Note that you can pass a toy's id instead of the whole toy object
  Kid.objects.get(id=kid_id).chores.remove(chore_id)
  messages.success(request, "SUCCESS YES")
  return redirect('kids_detail', kid_id=kid_id)

If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?

return resolver._reverse_with_prefix(view, prefix, *args, **kwargs)

File "/Users/thomasthephasdin/.local/share/virtualenvs/django-env-2RLhBifv/lib/python3.10/site-packages/django/urls/resolvers.py", line 828, in _reverse_with_prefix raise NoReverseMatch(msg) django.urls.exceptions.NoReverseMatch: Reverse for 'delete_chore' with arguments '(5,)' not found. 1 pattern(s) tried: ['kids/(?P[0-9]+)/assoc_chore/(?P[0-9]+)/\Z']

What is your best guess as to the source of the problem?

i think i'm just missing some small detail to bring over the right kid/chore id, to have it render on screen

What things have you already tried to solve the problem?

looked at django docs and examples, brought in necessary imports. could possibly be the "includes" method for django that might be needed to render html page but not sure

Paste a link to your repository here https://github.com/tthephas/Chore-Tracker

code should be on "deletemessage" branch

timmshinbone commented 1 year ago

Share the code in the view template for your delete, I think there's a problem with it.

tthephas commented 1 year ago

from the page where its rendering?

            <div class="card-action">
              <form action="{% url 'delete_chore' chore.id %}" method="POST">
                {% csrf_token %}
                <button type="submit" class="btn red">Confirm Done</button>

              </form>
            </div>
tthephas commented 1 year ago

i added "kid.id" after the delete chore function and it now renders, but clicking button doesnt do anything.

timmshinbone commented 1 year ago

We'll take a look after my meeting

tthephas commented 1 year ago

ok thanks

tthephas commented 1 year ago

still not sure how to get this message window to come up. pressing delete doesnt render anything

timmshinbone commented 1 year ago

Ok, let's jump into a breakout room about it, I'll slack ya

tthephas commented 1 year ago

thanks

tthephas commented 1 year ago

i was able to access the database, update the current balance (with a static number), then access the balance on teh chore (6 below), pass it thru the string, but i'm getting this error. seems very close to adding the number though

Reverse for 'delete_chore' with arguments '(3, 3, 6)' not found. 1 pattern(s) tried: ['kids/(?P[0-9]+)/unassoc_chore/(?P[0-9]+)/\Z']

tthephas commented 1 year ago

its the right chore, the right kid, the right amount, just not rendering for some reason.

tthephas commented 1 year ago

got bank account to update fine. but messages still not showing.