From 28270f5dd69690c6b5f7c69946fdf96f537b943b Mon Sep 17 00:00:00 2001 From: tomtom5152 Date: Wed, 29 Oct 2014 01:37:37 +0000 Subject: [PATCH] Started work on Person modeling --- .idea/PyRIGS.iml | 2 +- .idea/dataSources.xml | 2 +- RIGS/models.py | 25 ++++++++++++++++++++++++- RIGS/urls.py | 4 ++++ RIGS/views.py | 7 ++++++- 5 files changed, 36 insertions(+), 4 deletions(-) diff --git a/.idea/PyRIGS.iml b/.idea/PyRIGS.iml index 0396d4e5..28c5f8b9 100644 --- a/.idea/PyRIGS.iml +++ b/.idea/PyRIGS.iml @@ -11,7 +11,7 @@ - + diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml index 51b446d9..5cabf5c9 100644 --- a/.idea/dataSources.xml +++ b/.idea/dataSources.xml @@ -4,7 +4,7 @@ sqlite.xerial org.sqlite.JDBC - jdbc:sqlite:C:\Users\psytp\PycharmProjects\PyRIGS\db.sqlite3 + jdbc:sqlite:$PROJECT_DIR$/db.sqlite3 diff --git a/RIGS/models.py b/RIGS/models.py index c554f793..385a1fd1 100644 --- a/RIGS/models.py +++ b/RIGS/models.py @@ -2,6 +2,7 @@ from django.db import models from django.contrib.auth.models import AbstractUser from django.conf import settings import hashlib +import reversion # Create your models here. class Profile(AbstractUser): @@ -13,4 +14,26 @@ class Profile(AbstractUser): url = "" if settings.USE_GRAVATAR or settings.USE_GRAVATAR is None: url = "https://www.gravatar.com/avatar/" + hashlib.md5(self.email).hexdigest() + "?d=identicon&s=500" - return url \ No newline at end of file + return url + +class ModelComment(models.Model): + user = models.ForeignKey(settings.AUTH_USER_MODEL) + postedAt = models.DateTimeField(auto_now=True) + + message = models.TextField() + +@reversion.register +class Person(models.Model): + name = models.CharField(max_length=50) + phone = models.CharField(max_length=15, blank=True, null=True) + email = models.EmailField(blank=True, null=True) + + address = models.TextField(blank=True, null=True) + + comments = models.ManyToManyField('ModelComment') + + def __unicode__(self): + string = self.name + if self.comments: + string += "*" + return string \ No newline at end of file diff --git a/RIGS/urls.py b/RIGS/urls.py index 55f2744f..2c137857 100644 --- a/RIGS/urls.py +++ b/RIGS/urls.py @@ -3,6 +3,7 @@ from django.contrib import admin from django.contrib.staticfiles.urls import static from django.conf import settings import RIGS +from RIGS import views urlpatterns = patterns('', # Examples: @@ -10,5 +11,8 @@ urlpatterns = patterns('', # url(r'^blog/', include('blog.urls')), url('^user/login/$', 'RIGS.views.login', name='login'), + + # People + url(r'^people/$', views.PersonIndex.as_view(), name='person') ) diff --git a/RIGS/views.py b/RIGS/views.py index 3bd17cd6..f7c4ec73 100644 --- a/RIGS/views.py +++ b/RIGS/views.py @@ -1,5 +1,7 @@ from django.shortcuts import render from django.http.response import HttpResponseRedirect +from django.views import generic +import models # Create your views here. def login(request, **kwargs): @@ -8,4 +10,7 @@ def login(request, **kwargs): return HttpResponseRedirect(request.REQUEST.get('next', '/')) else: from django.contrib.auth.views import login - return login(request) \ No newline at end of file + return login(request) + +class PersonIndex(generic.ListView): + model = models.Person \ No newline at end of file