Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 1 commit
  • 5 files changed
  • 0 comments
  • 1 contributor
14  Dentist/forms/diseases_form.py
@@ -2,7 +2,7 @@
2 2
 from django import forms
3 3
 from django.forms.widgets import CheckboxSelectMultiple
4 4
 from django.utils.safestring import mark_safe
5  
-from ..models import disease
  5
+from ..models import disease, patient_diseases, patient
6 6
 
7 7
 class MyCheckboxSelectMultiple(CheckboxSelectMultiple):
8 8
 	def render(self, name, value, attrs=None, choices=()):
@@ -11,12 +11,10 @@ def render(self, name, value, attrs=None, choices=()):
11 11
 		html = html.replace('</ul>', '')
12 12
 		html = html.replace('<li>', '')
13 13
 		html = html.replace('</li>', '<br />')
  14
+		html = html.replace('Choroba: ', '')
14 15
 		return mark_safe(html)
15 16
 
16  
-class DiseasesForm(forms.Form):
17  
-	diseases = disease.objects.all()
18  
-	diseases2 = forms.MultipleChoiceField(required=False,
19  
-        widget=MyCheckboxSelectMultiple, 
20  
-        choices=[(disease.id, disease.disease_name) for disease in diseases])
21  
-	
22  
-
  17
+class DiseasesForm(forms.Form):		
  18
+	diseases = forms.ModelMultipleChoiceField(queryset=disease.objects.all(),
  19
+                                                    widget=MyCheckboxSelectMultiple(),
  20
+                                                    required=False)			
BIN  Dentist/forms/diseases_form.pyc
Binary file not shown
12  Dentist/templates/diseases.html
... ...
@@ -1,9 +1,11 @@
1 1
 {% extends 'base.html' %}
2 2
 
3 3
 {% block content %}
4  
-Moje choroby:<br />
5  
-{% for field in form %}
6  
-	{{ field }}
7  
-{% endfor %}
8  
-
  4
+Moje choroby:
  5
+<form action="/diseases/" method="post"> {% csrf_token %}
  6
+	{% for field in form %}
  7
+		{{ field }}
  8
+	{% endfor %}
  9
+	<p><input type="submit" value="Zapisz" /></p>
  10
+</form>
9 11
 {% endblock %}
16  Dentist/views.py
@@ -9,6 +9,7 @@
9 9
 from forms.user_form import UserForm
10 10
 from forms.patient_form import PatientForm
11 11
 from forms.diseases_form import DiseasesForm
  12
+from django.contrib.auth.decorators import login_required
12 13
 
13 14
 def register(request):
14 15
     if request.method == 'POST':
@@ -37,7 +38,20 @@ def register(request):
37 38
         form_patient = PatientForm
38 39
     return render(request, 'register.html', {'form': form, 'form_patient': form_patient})
39 40
 
  41
+#@login_required
40 42
 def diseases(request):
41  
-    form = DiseasesForm
  43
+    if request.POST:
  44
+        form = DiseasesForm(request.POST)
  45
+        if form.is_valid():
  46
+            for disease2 in request.POST.getlist('diseases'):
  47
+                pat = patient.objects.get(user=3)
  48
+                dis = disease.objects.get(id=disease2)
  49
+                pat_dis = patient_diseases(patient=pat,disease=dis, date=datetime.datetime.now().date())
  50
+                pat_dis.save()
  51
+            return HttpResponseRedirect('/index/')
  52
+        else:
  53
+            return render(request, 'test.html', {'form': request.POST})
  54
+    else:
  55
+        form = DiseasesForm
42 56
     return render(request, 'diseases.html', {'form': form})
43 57
     
BIN  Dentist/views.pyc
Binary file not shown

No commit comments for this range

Something went wrong with that request. Please try again.