Modify models

parent 326ca66c
# Generated by Django 2.1.2 on 2018-10-30 08:26
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0006_auto_20181029_2025'),
]
operations = [
migrations.AlterField(
model_name='raspi',
name='status',
field=models.CharField(choices=[('UP', 'UP'), ('DOWN', 'DOWN')], max_length=5),
),
]
# Generated by Django 2.1.2 on 2018-10-30 08:28
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0007_auto_20181030_0826'),
]
operations = [
migrations.AlterField(
model_name='raspi',
name='status',
field=models.CharField(choices=[('UP', 'UP'), ('DOWN', 'DOWN')], default='UP', max_length=5),
),
]
......@@ -20,8 +20,8 @@ class Patient(models.Model):
class Raspi(models.Model):
STATUS_CHOICES = [
('up', 'up'),
('down', 'down'),
('UP', 'UP'),
('DOWN', 'DOWN'),
]
ip = models.CharField(max_length=50)
status = models.CharField(max_length=5, choices=STATUS_CHOICES)
status = models.CharField(max_length=5, choices=STATUS_CHOICES, default="UP")
......@@ -10,6 +10,7 @@
<a class="navbar-brand" href="{% url 'index' %}">
<img width="30" height="30" src="{% static "heart.png" %}" alt="icon"> PyPrevention </a>
<center>
<a class="btn btn-dark" type="button" href="{% url 'index' %}">Home</a>
<a class="btn btn-dark" type="button" href="{% url 'dashboard' %}">Dashboard</a>
</center>
{% if user.is_authenticated %}
......
......@@ -12,7 +12,7 @@
<h5 class="card-title">{{doctor.first_name}} {{doctor.last_name}}</h5>
<p class="card-text">Email : {{doctor.email}}</p>
<p class="card-text">Address : {{doctor.address}}</p>
<a href="#" class="btn btn-dark">Modify</a>
<a href="{% url 'update_doctor' id=doctor.id %}" class="btn btn-dark">Modify</a>
<a href="{% url 'delete_doctor' id=doctor.id %}" class="btn btn-danger">Delete</a>
</div>
</div>
......
......@@ -19,7 +19,7 @@
{% else %}
<p> Status : <span class="badge badge-secondary">Unknown</span> </p>
{% endif %}
<a href="#" class="btn btn-dark">Modify</a>
<a href="{% url 'update_raspi' id=pi.id %}" class="btn btn-dark">Modify</a>
<a href="{% url 'delete_raspi' id=pi.id %}" class="btn btn-danger">Delete</a>
</center>
</div>
......
......@@ -13,7 +13,7 @@
<h5 class="card-title">{{patient.first_name}} {{patient.last_name}}</h5>
<p class="card-text">Date of birth : {{patient.date_of_birth}}</p>
<p class="card-text">Doctor : {{patient.doctor.first_name}} {{patient.doctor.last_name}}</p>
<a href="#" class="btn btn-dark">Modify</a>
<a href="{% url 'update_patient' id=patient.id %}" class="btn btn-dark">Modify</a>
<a href="{% url 'delete_patient' id=patient.id %}" class="btn btn-danger">Delete</a>
</center>
</div>
......
......@@ -19,4 +19,7 @@ urlpatterns = [
path('delete/raspi/<int:id>', views.delete_raspi, name='delete_raspi'),
path('delete/doctor/<int:id>', views.delete_doctor, name='delete_doctor'),
path('delete/patient/<int:id>', views.delete_patient, name='delete_patient'),
path('update/raspi/<int:id>', views.update_raspi, name='update_raspi'),
path('update/doctor/<int:id>', views.update_doctor, name='update_doctor'),
path('update/patient/<int:id>', views.update_patient, name='update_patient'),
]
......@@ -101,3 +101,49 @@ def delete_patient(request, id):
def delete_doctor(request, id):
u = Doctor.objects.filter(id=id).delete()
return redirect('doctors')
@login_required
def update_raspi(request, id):
instance = Raspi.objects.filter(id=id).last()
if request.method == "POST":
form = RaspiForm(request.POST or None, instance=instance)
if form.is_valid():
instance.ip = form.cleaned_data['ip']
instance.status = form.cleaned_data['status']
instance.save()
return redirect('interface')
else:
form = RaspiForm(request.POST or None, instance=instance)
return render(request, 'raspi_add.html', {'form': form})
@login_required
def update_patient(request, id):
instance = Patient.objects.filter(id=id).last()
if request.method == "POST":
form = PatientForm(request.POST or None, instance=instance)
if form.is_valid():
instance.first_name = form.cleaned_data['first_name']
instance.last_name = form.cleaned_data['last_name']
instance.date_of_birth = form.cleaned_data['date_of_birth']
instance.doctor = form.cleaned_data['doctor']
instance.save()
return redirect('patients')
else:
form = PatientForm(request.POST or None, instance=instance)
return render(request, 'patient_add.html', {'form': form})
@login_required
def update_doctor(request, id):
instance = Doctor.objects.filter(id=id).last()
if request.method == "POST":
form = DoctorForm(request.POST or None, instance=instance)
if form.is_valid():
instance.first_name = form.cleaned_data['first_name']
instance.last_name = form.cleaned_data['last_name']
instance.email = form.cleaned_data['email']
instance.address = form.cleaned_data['address']
instance.save()
return redirect('doctors')
else:
form = DoctorForm(request.POST or None, instance=instance)
return render(request, 'doctor_add.html', {'form': form})
No preview for this file type
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