Commit c9580eb2 authored by Gab De Jesus's avatar Gab De Jesus

reviews/views.py now passes a ReviewForm (reviews/forms.py) to index.html,...

reviews/views.py now passes a ReviewForm (reviews/forms.py) to index.html, autogenerating the form fields and allowing users to upload their own reviews of currently existing profs
parent 67580d3f
...@@ -20,5 +20,5 @@ from reviews import views as reviews_views ...@@ -20,5 +20,5 @@ from reviews import views as reviews_views
urlpatterns = [ urlpatterns = [
url(r'^admin/', admin.site.urls), url(r'^admin/', admin.site.urls),
url(r'^$', reviews_views.index, name="reviews_index") url(r'^$', reviews_views.index, name="reviews_index"),
] ]
No preview for this file type
from django.forms import ModelForm
from .models import Prof, Review
class ReviewForm(ModelForm):
class Meta:
model = Review
fields = ['message', 'rating', 'prof']
\ No newline at end of file
...@@ -40,7 +40,14 @@ ...@@ -40,7 +40,14 @@
<td>{{ review.updated_at }}</td> <td>{{ review.updated_at }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>
<!-- Make the form for uploading a new review -->
<h1>New review</h1>
<form method="POST">
{% csrf_token %}
{{ upload_form.as_p }}
<button type="submit">Save</button>
</form>
</body> </body>
</html> </html>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
</body>
</html>
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from .models import Review from .models import Review, Prof
from .forms import ReviewForm
# Create your views here. # Create your views here.
def index(request): def index(request):
if(request.method=='POST'):
form = ReviewForm(request.POST)
if(form.is_valid()):
form.save()
reviews = Review.objects.all() reviews = Review.objects.all()
return render(request, 'index.html', {'reviews': reviews}) profs = Prof.objects.all()
\ No newline at end of file upload_form = ReviewForm()
return render(request, 'index.html', {'reviews': reviews, 'upload_form': upload_form, 'profs': profs})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment