diff --git a/smash/web/forms.py b/smash/web/forms.py new file mode 100644 index 0000000000000000000000000000000000000000..d69a75ed2666c194553c5937744e9ed376876d9e --- /dev/null +++ b/smash/web/forms.py @@ -0,0 +1,7 @@ +from django import forms +from .models import * + +class SubjectAddForm(ModelForm) + class Meta + model = Subject + fields = '__all__' diff --git a/smash/web/templates/subjects/add.html b/smash/web/templates/subjects/add.html index c8f5de44af9b0e660c2fe6c467e7df8823ac1071..c08af0aac038a3678f4074c0146a9f490ab8d99d 100644 --- a/smash/web/templates/subjects/add.html +++ b/smash/web/templates/subjects/add.html @@ -18,18 +18,23 @@ {% block maincontent %} -%TODO: add adding - {% block title %}{{object_name}} Form{% endblock %} {% block content %} -<form action="" method="post">{% csrf_token %} -<table> -{{form}} -</table> -<input type="submit" value="Save {{object_name}}"/></form> +<form method="post" action=""> + {{ formset.as_ul }} + {% csrf_token %} + + + <button type="submit" class="btn btn-block btn-success">Add</button> + + <a href="{% url 'web.views.subjects' %}" class="btn btn-block btn-default">Cancel</a> +</form> {% endblock %} + + + {% endblock maincontent %} {% block scripts %} diff --git a/smash/web/templates/subjects/index.html b/smash/web/templates/subjects/index.html index 659c315db89ffbf551f2b7eaf6cc67a5c07017a4..2544d62c587efd92e482fcc44a3b0799c7b5cfd9 100644 --- a/smash/web/templates/subjects/index.html +++ b/smash/web/templates/subjects/index.html @@ -19,9 +19,9 @@ {% block maincontent %} <div> - <a class="btn btn-app"> - <a href="{% url 'web.views.subjectadd' %}"><i class="fa fa-plus"></i> Add new subject - </a> + <a href="{% url 'web.views.subjectadd' %}" class="btn btn-app"> + <i class="fa fa-plus"></i> + Add new subject</a> </div> <div class="box-body"> diff --git a/smash/web/views.py b/smash/web/views.py index dc6ac3026acb23c3cf8f3000c160ed5e37454eeb..98eb5fa72781d49f55bca56c32c537cb15327478 100644 --- a/smash/web/views.py +++ b/smash/web/views.py @@ -3,7 +3,9 @@ from django.http import HttpResponse from django.template import loader from django.views import generic from .models import * -import auth +from django.forms import modelformset_factory +from django.shortcuts import render +# import auth # Create your views here. def index(request): @@ -49,11 +51,16 @@ def subjects(request): return HttpResponse(template.render(context,request)) -def subjectadd(request,CreateView): - template = loader.get_template("subjects/add.html") - model = Subject +def subjectadd(request): + SubjectFormSet = modelformset_factory(Subject , fields='__all__') + if request.method == 'POST': + formset = SubjectFormSet(request.POST, request.FILES) + if formset.is_valid(): + formset.save() + else: + formset = SubjectFormSet(queryset=Subject.objects.none()) + return render(request, 'subjects/add.html', {'formset': formset}) - return HttpResponse(template.render(model,request)) def doctors(request): doctors_list = Worker.objects.order_by('-lastName')