Events app added. Models v1

This commit is contained in:
Johnson Chetty 2012-08-03 22:34:40 +02:00
parent 5e3317e4c7
commit 993ffc69d2
3 changed files with 70 additions and 0 deletions

0
itf/events/__init__.py Normal file
View File

9
itf/events/admin.py Executable file
View File

@ -0,0 +1,9 @@
from django.contrib import admin
from models import *
#class EventAdmin(admin.ModelAdmin):
admin.site.register(Event)

61
itf/events/models.py Normal file
View File

@ -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