From 993ffc69d27506f9ca82d0f962844e71efd9b6de Mon Sep 17 00:00:00 2001 From: Johnson Chetty Date: Fri, 3 Aug 2012 22:34:40 +0200 Subject: [PATCH] Events app added. Models v1 --- itf/events/__init__.py | 0 itf/events/admin.py | 9 +++++++ itf/events/models.py | 61 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 itf/events/__init__.py create mode 100755 itf/events/admin.py create mode 100644 itf/events/models.py diff --git a/itf/events/__init__.py b/itf/events/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/itf/events/admin.py b/itf/events/admin.py new file mode 100755 index 0000000..ab7f7d8 --- /dev/null +++ b/itf/events/admin.py @@ -0,0 +1,9 @@ +from django.contrib import admin +from models import * + +#class EventAdmin(admin.ModelAdmin): + + +admin.site.register(Event) + + diff --git a/itf/events/models.py b/itf/events/models.py new file mode 100644 index 0000000..5a44f0e --- /dev/null +++ b/itf/events/models.py @@ -0,0 +1,61 @@ +from django.db import models +from app.models import ItfModel +from django.contrib.auth.models import User +from datetime import datetime +from django.contrib.localflavor.in_.forms import INZipCodeField +#from ox.django.fields import DictField +from django.contrib.contenttypes.models import ContentType +from django.contrib.contenttypes import generic +from itfprofiles.models import Location + + +class Event(ItfModel): + #ItfModel stuff: + #form_names = ['PersonForm', 'PopupPersonForm'] + #fts_fields = ['first_name', 'last_name', 'email', 'about'] + + title = models.CharField(max_length=1024) + oneliner = models.CharField(max_length=1024,help_text="Event slogan/one liner") + description = models.TextField(blank=True, null=True) + locations = generic.GenericRelation("Location") + start_date = models.DateTimeField() + end_date = models.DateTimeField() + booking_link = models.URLField(blank=True, null=True, help_text="Ticket booking") + tel_no = models.CharField(max_length=100, blank=True) + + image = models.ImageField(upload_to='images/', blank=True, null=True) + +#Entities and Connections - + connections = generic.GenericRelation("Connection") + + + def __unicode__(self): + return "%s" % (self.title,) + + def get_title(self): + return self.__unicode__() + + def get_dict(self): + links = self.connections.all().order_by('link_type') + link_keys = self.connections.all().values_list['link_type'].distinct() + + conn = dict() + for key in link_keys: + conn[key]= [obj for obj in links if obj.type==key] + #add conn keys to main dict + return { + 'title': self.title, + 'oneliner': self.oneliner, + 'description': self.description + } + +class Connection(models.Model): + link_type = models.CharField(max_length=255) + extra_text = models.CharField(max_length=1024) + content_type = models.ForeignKey(ContentType) + object_id = models.PositiveIntegerField() + content_object = generic.GenericForeignKey('content_type', 'object_id') + + def __unicode__(self): + return self.link_type +