-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Current status of play view/form/template (non-functional) #122
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work, will run the app to see this in action ...
|
||
def __init__(self, *args, **kwargs): | ||
matching_tunes_queryset = kwargs.pop("matching_tunes_queryset", None) | ||
super(PlayForm, self).__init__(*args, **kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Py 2, starting v3 you can do super()
play_form = PlayForm(initial={"suggested_tune": suggested_tune}) | ||
return render(request, "tune/play.html", locals()) | ||
# play_form = PlayForm([tune.id for tune in tunes]) | ||
suggested_tune = tunes.first() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where I said tunes[0] previously, first() and last() also work
matching_tunes_queryset = RepertoireTune.objects.filter(id__in=matching_tunes) | ||
play_form = PlayForm( | ||
request.POST or None, | ||
initial={"matching_tunes": matching_tunes}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to run this, so here you want to form pre-populated ...
if choice == "Play!": | ||
suggested_tune.last_played = timezone.now() | ||
suggested_tune.save() | ||
messages.success(request, f"Played {suggested_tune.tune.title}!") | ||
else: | ||
print(f"playform invalid: {play_form.errors}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error should show up in the form in the template?
@@ -18,7 +18,10 @@ | |||
<p> Okay? </p> | |||
<form method="post" action="{% url 'tune:tune_play' %}"> | |||
{% csrf_token %} | |||
{{ play_form.suggested_tune }} | |||
{% for value in play_form.initial.matching_tunes %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can not be done with the model form out of the box?
No description provided.