From c852f4c62db0e0f2060bc6ae7eb5b395e9de4ff1 Mon Sep 17 00:00:00 2001
From: "piotr.atyjaszyk" <piotrmk1@gmail.com>
Date: Wed, 23 Nov 2016 12:06:40 +0100
Subject: [PATCH] Modified user to use languages table, made thumbnails display
 next to user

---
 smash/smash/settings.py |  1 +
 smash/smash/urls.py     |  6 ++++--
 smash/web/admin.py      |  9 ++++++++-
 smash/web/models.py     | 22 ++++++++++++++++------
 smash/web/urls.py       |  2 +-
 smash/web/views.py      | 18 +++++++++---------
 6 files changed, 39 insertions(+), 19 deletions(-)

diff --git a/smash/smash/settings.py b/smash/smash/settings.py
index 327f508e..cff7e49c 100644
--- a/smash/smash/settings.py
+++ b/smash/smash/settings.py
@@ -99,5 +99,6 @@ USE_TZ = True
 # https://docs.djangoproject.com/en/1.10/howto/static-files/
 
 STATIC_URL = '/static/'
+MEDIA_URL = '/media/'
 
 from local_settings import *
diff --git a/smash/smash/urls.py b/smash/smash/urls.py
index b26bd979..53e2f4c5 100644
--- a/smash/smash/urls.py
+++ b/smash/smash/urls.py
@@ -16,10 +16,12 @@ Including another URLconf
 
 from django.conf.urls import url, include
 from django.contrib import admin
+from django.conf import settings
+from django.conf.urls.static import static
 
 import web.urls
 
 urlpatterns = [
     url(r'^admin/', admin.site.urls),
-    url(r'^', include(web.urls))
-]
+    url(r'', include(web.urls))
+] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
diff --git a/smash/web/admin.py b/smash/web/admin.py
index 33e2f64f..afda4983 100644
--- a/smash/web/admin.py
+++ b/smash/web/admin.py
@@ -1,13 +1,20 @@
 from django.contrib import admin
 
 from models import *
+
+
+class LanguageAdmin(admin.ModelAdmin):
+    list_display = ('name','image_img')
+
+
+
 # Register your models here.
 admin.site.register(Subject)
 admin.site.register(Visit)
 admin.site.register(Item)
 admin.site.register(Room)
 admin.site.register(AppType)
-admin.site.register(Language)
+admin.site.register(Language, LanguageAdmin)
 admin.site.register(Worker)
 admin.site.register(FlyingTeam)
 admin.site.register(Avaibility)
diff --git a/smash/web/models.py b/smash/web/models.py
index d4a477f1..939c9915 100644
--- a/smash/web/models.py
+++ b/smash/web/models.py
@@ -5,11 +5,26 @@ from django.utils import timezone
 from django.contrib.auth.models import User
 
 
+
+
+class Language (models.Model):
+    name = models.CharField(max_length = 20)
+    image = models.ImageField()
+    def __str__(self):
+        return self.name
+    def image_img(self):
+        if self.image:
+            return u'<img src="%s" />' % (self.image.url)
+        else:
+            return 'No image'
+    image_img.short_description = 'Thumb'
+    image_img.allow_tags = True
+
 class Subject(models.Model):
     sex = models.CharField(max_length=1)
     firstName = models.CharField(max_length=50)
     lastName = models.CharField(max_length=50)
-    language = models.CharField(max_length=20)
+    languages = models.ManyToManyField(Language)
     phoneNo = models.CharField(max_length=20)
     email = models.EmailField()
     born = models.DateField()
@@ -58,11 +73,6 @@ class AppType (models.Model):
     apRestTime = models.IntegerField()
 
 
-class Language (models.Model):
-    name = models.CharField(max_length = 20)
-    image = models.ImageField()
-
-
 class Worker (models.Model):
     languages = models.ManyToManyField(Language)
     appointments = models.ManyToManyField('Appointment')
diff --git a/smash/web/urls.py b/smash/web/urls.py
index 44816932..f1d5a7e6 100644
--- a/smash/web/urls.py
+++ b/smash/web/urls.py
@@ -22,5 +22,5 @@ urlpatterns = [
     url(r'doctors$', views.doctors, name='web.views.doctors'),
     url(r'equipment_and_rooms$', views.equipment_and_rooms, name='web.views.equipment_and_rooms'),
     url(r'mail_templates$', views.mail_templates, name='web.views.mail_templates'),
-	url(r'$', views.index, name='web.views.index')
+	url(r'^$', views.index, name='web.views.index')
 ]
diff --git a/smash/web/views.py b/smash/web/views.py
index 48a6c3c7..e3312162 100644
--- a/smash/web/views.py
+++ b/smash/web/views.py
@@ -1,40 +1,40 @@
 from django.shortcuts import render
 from django.http import HttpResponse
 from django.template import loader
-
+from django.views import generic
 
 # Create your views here.
 def index(request):
 	template = loader.get_template("index.html")
-	return HttpResponse(template.render({    
+	return HttpResponse(template.render({
 	}), request)
 
 
 def assignments(request):
 	template = loader.get_template("assignments/index.html")
-	return HttpResponse(template.render({    
+	return HttpResponse(template.render({
 	}), request)
 
 
 def subjects(request):
 	template = loader.get_template("subjects/index.html")
-	return HttpResponse(template.render({    
+	return HttpResponse(template.render({
 	}), request)
 
 
 def doctors(request):
 	template = loader.get_template("doctors/index.html")
-	return HttpResponse(template.render({    
+	return HttpResponse(template.render({
 	}), request)
-	
-	
+
+
 def equipment_and_rooms(request):
 	template = loader.get_template("equipment_and_rooms/index.html")
-	return HttpResponse(template.render({    
+	return HttpResponse(template.render({
 	}), request)
 
 
 def mail_templates(request):
 	template = loader.get_template("mail_templates/index.html")
-	return HttpResponse(template.render({    
+	return HttpResponse(template.render({
 	}), request)
-- 
GitLab