add doctor + doctors

parent 726c1a72
from django import forms
from .models import *
class PatientForm(forms.ModelForm):
class Meta:
model = Patient
fields = ('first_name', 'last_name','date_of_birth','doctor')
class DoctorForm(forms.ModelForm):
class Meta:
model = Doctor
fields = ('first_name', 'last_name','email','address')
{% extends 'base.html' %}
{% block content %}
<div class="container">
<div class="jumbotron mt-5">
<div class="container">
<h1 class="display-4">New doctor</h1>
<form method="POST" class="post-form">{% csrf_token %}
{{ form.as_p }}
<button type="submit" class="save btn btn-success">Save</button>
</form>
</div>
</div>
{% endblock %}
{% extends 'base.html' %}
{% block content %}
<div class="container">
{% load static %}
<div class="row mt-5">
{% for doctor in doctors %}
<div class="col">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="{% static "doctor.jpg" %}" alt="Card image cap">
<div class="card-body mx-auto">
<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-primary">Soigne moi fdp</a>
</div>
</div>
</div>
{% if forloop.counter|divisibleby:"4" or forloop.last %}
</div> <!--end row-->
{% endif %}
{% endfor %}
</div>
{% endblock %}
{% extends 'base.html' %}
{% block content %}
<h1>New patient</h1>
<form method="POST" class="post-form">{% csrf_token %}
{{ form.as_p }}
<button type="submit" class="save btn btn-default">Save</button>
</form>
{% endblock %}
......@@ -3,7 +3,7 @@
{% block content %}
<div class="row">
{% for item in items %}
{% for patient in patients %}
<div class="col">
<a href="https://www.w3schools.com">
<div class="card mx-auto" style="width: 18rem; height:10rem;">
......@@ -11,7 +11,7 @@
<img class="card-img-top" src="https://www.cadredesante.com/spip/local/cache-vignettes/L379xH251/hopital-dessin-g-7f972.jpg" alt="Card image cap">
<div class="card-body">
<h5 class="card-title">Mes patients {{item.title}}</h5>
<h5 class="card-title">Mes patients {{patient.first_name}}</h5>
</div>
</div>
</a>
......
......@@ -10,4 +10,8 @@ urlpatterns = [
path('logout', views.logout_view, name='logout'),
url(r'^accounts/login/$', views.login, name='login'),
url(r'^home/$', views.home, name='home'),
path('patient/new', views.patient_new, name='patient_new'),
path('doctor/new', views.doctor_new, name='doctor_new'),
path('doctors', views.doctors, name='doctors'),
]
......@@ -2,7 +2,13 @@ from django.shortcuts import render, redirect
from django.http import HttpResponse
from django.contrib.auth.decorators import login_required
from django.contrib.auth import logout
from .forms import *
from .models import *
import random
def patient_new(request):
form = PatientForm()
return render(request, 'patient_add.html', {'form': form})
@login_required
def logout_view(request):
......@@ -13,8 +19,24 @@ def index(request):
return render(request, 'index.html')
def test(request):
items = [{"title": "ok1"}, {"title" : "ok2"}]
return render(request, 'test.html', {"items" : items})
patients = Patient.objects.all()
return render(request, 'test.html', {"patients" : patients})
def doctor_new(request):
if request.method == "POST":
form = DoctorForm(request.POST)
if form.is_valid():
doctor = Doctor()
doctor.username = random.randint(0,1000)
doctor.first_name = form.cleaned_data['first_name']
doctor.last_name = form.cleaned_data['last_name']
doctor.email = form.cleaned_data['email']
doctor.address = form.cleaned_data['address']
doctor.save()
return redirect('doctors')
else:
form = DoctorForm()
return render(request, 'doctor_add.html', {'form': form})
@login_required
def api(request):
......@@ -26,3 +48,7 @@ def login(request):
def home(request):
return render(request, 'home.html')
def doctors(request):
doctors = Doctor.objects.all()
return render(request, 'doctors.html', {"doctors" : doctors})
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