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
urlpatterns = [
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 @@
<td>{{ review.updated_at }}</td>
</tr>
{% endfor %}
</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>
</html>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
</body>
</html>
\ No newline at end of file
from django.shortcuts import render
from .models import Review
from .models import Review, Prof
from .forms import ReviewForm
# Create your views here.
def index(request):
if(request.method=='POST'):
form = ReviewForm(request.POST)
if(form.is_valid()):
form.save()
reviews = Review.objects.all()
return render(request, 'index.html', {'reviews': reviews})
\ No newline at end of file
profs = Prof.objects.all()
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