Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: eltadziko/Dentist
base: 815848cf83
...
head fork: eltadziko/Dentist
compare: 6fc4cc4812
  • 1 commit
  • 5 files changed
  • 0 commit comments
  • 1 contributor
14 Dentist/forms/diseases_form.py
View
@@ -2,7 +2,7 @@
from django import forms
from django.forms.widgets import CheckboxSelectMultiple
from django.utils.safestring import mark_safe
-from ..models import disease
+from ..models import disease, patient_diseases, patient
class MyCheckboxSelectMultiple(CheckboxSelectMultiple):
def render(self, name, value, attrs=None, choices=()):
@@ -11,12 +11,10 @@ def render(self, name, value, attrs=None, choices=()):
html = html.replace('</ul>', '')
html = html.replace('<li>', '')
html = html.replace('</li>', '<br />')
+ html = html.replace('Choroba: ', '')
return mark_safe(html)
-class DiseasesForm(forms.Form):
- diseases = disease.objects.all()
- diseases2 = forms.MultipleChoiceField(required=False,
- widget=MyCheckboxSelectMultiple,
- choices=[(disease.id, disease.disease_name) for disease in diseases])
-
-
+class DiseasesForm(forms.Form):
+ diseases = forms.ModelMultipleChoiceField(queryset=disease.objects.all(),
+ widget=MyCheckboxSelectMultiple(),
+ required=False)
BIN  Dentist/forms/diseases_form.pyc
View
Binary file not shown
12 Dentist/templates/diseases.html
View
@@ -1,9 +1,11 @@
{% extends 'base.html' %}
{% block content %}
-Moje choroby:<br />
-{% for field in form %}
- {{ field }}
-{% endfor %}
-
+Moje choroby:
+<form action="/diseases/" method="post"> {% csrf_token %}
+ {% for field in form %}
+ {{ field }}
+ {% endfor %}
+ <p><input type="submit" value="Zapisz" /></p>
+</form>
{% endblock %}
16 Dentist/views.py
View
@@ -9,6 +9,7 @@
from forms.user_form import UserForm
from forms.patient_form import PatientForm
from forms.diseases_form import DiseasesForm
+from django.contrib.auth.decorators import login_required
def register(request):
if request.method == 'POST':
@@ -37,7 +38,20 @@ def register(request):
form_patient = PatientForm
return render(request, 'register.html', {'form': form, 'form_patient': form_patient})
+#@login_required
def diseases(request):
- form = DiseasesForm
+ if request.POST:
+ form = DiseasesForm(request.POST)
+ if form.is_valid():
+ for disease2 in request.POST.getlist('diseases'):
+ pat = patient.objects.get(user=3)
+ dis = disease.objects.get(id=disease2)
+ pat_dis = patient_diseases(patient=pat,disease=dis, date=datetime.datetime.now().date())
+ pat_dis.save()
+ return HttpResponseRedirect('/index/')
+ else:
+ return render(request, 'test.html', {'form': request.POST})
+ else:
+ form = DiseasesForm
return render(request, 'diseases.html', {'form': form})
BIN  Dentist/views.pyc
View
Binary file not shown

No commit comments for this range

Something went wrong with that request. Please try again.