Add CommonEvent model

This commit is contained in:
Michael Hall 2018-03-17 15:29:17 -04:00
parent 6228e0e003
commit 555ccf3fab
4 changed files with 128 additions and 3 deletions

View file

@ -5,7 +5,8 @@ from django.utils.safestring import mark_safe
from .models.locale import Language, Continent, Country, SPR, City
from .models.profiles import UserProfile, Organization, Team, Member, Category, Topic
from .models.search import Searchable
from .models.events import Place, Event, EventPhoto, Attendee
from .models.events import Place, Event, EventPhoto, CommonEvent, Attendee
from .models.events import Place, Event, CommonEvent, Attendee
admin.site.register(Language)
admin.site.register(Continent)
@ -66,6 +67,15 @@ class EventPhotoAdmin(admin.ModelAdmin):
view.short_description = 'Photo'
admin.site.register(EventPhoto, EventPhotoAdmin)
class CommonEventAdmin(admin.ModelAdmin):
raw_id_fields = ('place', 'city', 'spr', 'country')
list_display = ('__str__', 'participant_count', 'organization', 'start_time', 'country', 'spr', 'city')
ordering = ('-start_time',)
def participant_count(self, event):
return event.participating_events.all().count()
participant_count.short_description = 'Participants'
admin.site.register(CommonEvent, CommonEventAdmin)
class MemberAdmin(admin.ModelAdmin):
list_display = ('__str__', 'role')
list_filter = ('role', 'team')

View file

@ -0,0 +1,82 @@
# Generated by Django 2.0 on 2018-03-12 18:57
import datetime
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('events', '0016_make_searchable_uri_unique'),
]
operations = [
migrations.CreateModel(
name='CommonEvent',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=150, verbose_name='Event Name')),
('start_time', models.DateTimeField(db_index=True, help_text='Local date and time that the event starts', verbose_name='Local Start Time')),
('end_time', models.DateTimeField(db_index=True, help_text='Local date and time that the event ends', verbose_name='Local End Time')),
('summary', models.TextField(blank=True, help_text='Summary of the Event', null=True)),
('web_url', models.URLField(blank=True, help_text='URL for the event', null=True, verbose_name='Website')),
('announce_url', models.URLField(blank=True, help_text='URL for the announcement', null=True, verbose_name='Announcement')),
('created_time', models.DateTimeField(db_index=True, default=datetime.datetime.now, help_text='the date and time when the event was created')),
('tags', models.CharField(blank=True, max_length=128, null=True, verbose_name='Keyword Tags')),
('category', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='events.Category')),
('city', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='events.City')),
('country', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='events.Country')),
],
),
migrations.AddField(
model_name='organization',
name='owner_profile',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='owned_orgs', to='events.UserProfile'),
),
migrations.AlterField(
model_name='team',
name='organization',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='teams', to='events.Organization'),
),
migrations.AlterField(
model_name='team',
name='owner_profile',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='owned_teams', to='events.UserProfile'),
),
migrations.AddField(
model_name='commonevent',
name='created_by',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='events.UserProfile'),
),
migrations.AddField(
model_name='commonevent',
name='organization',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='events.Organization'),
),
migrations.AddField(
model_name='commonevent',
name='parent',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='sub_events', to='events.CommonEvent'),
),
migrations.AddField(
model_name='commonevent',
name='place',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='events.Place'),
),
migrations.AddField(
model_name='commonevent',
name='spr',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='events.SPR'),
),
migrations.AddField(
model_name='commonevent',
name='topics',
field=models.ManyToManyField(blank=True, to='events.Topic'),
),
migrations.AddField(
model_name='event',
name='parent',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='participating_events', to='events.CommonEvent'),
),
]

View file

@ -55,6 +55,7 @@ class PlaceSerializer(serializers.ModelSerializer):
class Event(models.Model):
name = models.CharField(max_length=150, verbose_name=_('Event Name'))
team = models.ForeignKey(Team, on_delete=models.CASCADE)
parent = models.ForeignKey('CommonEvent', related_name='participating_events', null=True, blank=True, on_delete=models.SET_NULL)
start_time = models.DateTimeField(help_text=_('Local date and time that the event starts'), verbose_name=_('Local Start Time'), db_index=True)
end_time = models.DateTimeField(help_text=_('Local date and time that the event ends'), verbose_name=_('Local End Time'), db_index=True)
@ -196,3 +197,33 @@ class EventPhoto(models.Model):
processors=[ResizeToFill(250, 187)],
format='JPEG',
options={'quality': 60})
class CommonEvent(models.Model):
name = models.CharField(max_length=150, verbose_name=_('Event Name'))
organization = models.ForeignKey(Organization, null=True, blank=True, on_delete=models.CASCADE)
parent = models.ForeignKey('CommonEvent', related_name='sub_events', null=True, blank=True, on_delete=models.SET_NULL)
start_time = models.DateTimeField(help_text=_('Local date and time that the event starts'), verbose_name=_('Local Start Time'), db_index=True)
end_time = models.DateTimeField(help_text=_('Local date and time that the event ends'), verbose_name=_('Local End Time'), db_index=True)
summary = models.TextField(help_text=_('Summary of the Event'), blank=True, null=True)
country = models.ForeignKey(Country, null=True, blank=True, on_delete=models.SET_NULL)
spr = models.ForeignKey(SPR, null=True, blank=True, on_delete=models.SET_NULL)
city = models.ForeignKey(City, null=True, blank=True, on_delete=models.SET_NULL)
place = models.ForeignKey(Place, blank=True, null=True, on_delete=models.SET_NULL)
web_url = models.URLField(verbose_name=_('Website'), help_text=_('URL for the event'), max_length=200, blank=True, null=True)
announce_url = models.URLField(verbose_name=_('Announcement'), help_text=_('URL for the announcement'), max_length=200, blank=True, null=True)
created_by = models.ForeignKey(UserProfile, on_delete=models.CASCADE)
created_time = models.DateTimeField(help_text=_('the date and time when the event was created'), default=datetime.datetime.now, db_index=True)
category = models.ForeignKey('Category', on_delete=models.SET_NULL, blank=False, null=True)
topics = models.ManyToManyField('Topic', blank=True)
tags = models.CharField(verbose_name=_("Keyword Tags"), blank=True, null=True, max_length=128)
def __str__(self):
return self.name
>>>>>>> Add CommonEvent model

View file

@ -156,12 +156,14 @@ class Organization(models.Model):
name = models.CharField(max_length=256, null=False, blank=False)
site = models.ForeignKey(Site, on_delete=models.CASCADE)
owner_profile = models.ForeignKey(UserProfile, related_name='owned_orgs', blank=False, null=True, on_delete=models.SET_NULL)
def __str__(self):
return u'%s' % (self.name)
class Team(models.Model):
name = models.CharField(_("Team Name"), max_length=256, null=False, blank=False)
organization = models.ForeignKey(Organization, null=True, blank=True, on_delete=models.CASCADE)
organization = models.ForeignKey(Organization, related_name='teams', null=True, blank=True, on_delete=models.CASCADE)
description = models.TextField(help_text=_('Team Description'), blank=True, null=True)
@ -174,7 +176,7 @@ class Team(models.Model):
created_date = models.DateField(_("Date Created"), null=True, blank=True)
owner_profile = models.ForeignKey(UserProfile, related_name='owner', null=True, on_delete=models.CASCADE)
owner_profile = models.ForeignKey(UserProfile, related_name='owned_teams', null=True, on_delete=models.CASCADE)
admin_profiles = models.ManyToManyField(UserProfile, related_name='admins', blank=True)
contact_profiles = models.ManyToManyField(UserProfile, related_name='contacts', blank=True)