diff --git a/events/admin.py b/events/admin.py index 400fd89..5956063 100644 --- a/events/admin.py +++ b/events/admin.py @@ -5,7 +5,7 @@ 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, Attendee +from .models.events import Place, Event, EventPhoto, Attendee admin.site.register(Language) admin.site.register(Continent) @@ -59,6 +59,8 @@ class EventAdmin(admin.ModelAdmin): attendee_count.short_description = 'Attendees' admin.site.register(Event, EventAdmin) +admin.site.register(EventPhoto) + class MemberAdmin(admin.ModelAdmin): list_display = ('__str__', 'role') list_filter = ('role', 'team') diff --git a/events/forms.py b/events/forms.py index 4ea1808..9fe6f79 100644 --- a/events/forms.py +++ b/events/forms.py @@ -5,7 +5,7 @@ from django.utils.translation import ugettext_lazy as _ from django.contrib.auth.models import User from .models.profiles import Team, UserProfile -from .models.events import Event, Place +from .models.events import Event, Place, EventPhoto from datetime import time from time import strptime, strftime @@ -196,6 +196,11 @@ class NewTeamEventForm(forms.ModelForm): class DeleteEventForm(forms.Form): confirm = forms.BooleanField(label="Yes, delete event", required=True) +class UploadEventPhotoForm(forms.ModelForm): + class Meta: + model = EventPhoto + fields = ['src', 'title', 'caption'] + class NewPlaceForm(forms.ModelForm): class Meta: model = Place diff --git a/events/migrations/0017_add_event_images.py b/events/migrations/0017_add_event_images.py new file mode 100644 index 0000000..7ef9692 --- /dev/null +++ b/events/migrations/0017_add_event_images.py @@ -0,0 +1,31 @@ +# Generated by Django 2.0 on 2018-03-17 20:50 + +from django.db import migrations, models +import django.db.models.deletion +import imagekit.models.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('events', '0016_make_searchable_uri_unique'), + ] + + operations = [ + migrations.CreateModel( + name='EventPhoto', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=256)), + ('caption', models.TextField(blank=True, null=True)), + ('src', models.ImageField(upload_to='event_photos')), + ('event', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='photos', to='events.Event')), + ], + ), + migrations.AlterField( + model_name='userprofile', + name='avatar', + field=imagekit.models.fields.ProcessedImageField(default='http://www.gravatar.com/avatar/00000000000000000000000000000000.jpg?d=mm', upload_to='avatars', verbose_name='Photo Image'), + preserve_default=False, + ), + ] diff --git a/events/models/events.py b/events/models/events.py index 90cc63f..a0d96f4 100644 --- a/events/models/events.py +++ b/events/models/events.py @@ -6,6 +6,9 @@ from django.shortcuts import reverse from rest_framework import serializers +from imagekit.models import ImageSpecField +from imagekit.processors import ResizeToFill + from .locale import * from .profiles import * from .search import * @@ -183,4 +186,13 @@ class Attendee(models.Model): def __str__(self): return "%s at %s" % (self.user, self.event) - + +class EventPhoto(models.Model): + event = models.ForeignKey(Event, related_name='photos', on_delete=models.CASCADE) + title = models.CharField(max_length=256) + caption = models.TextField(null=True, blank=True) + src = models.ImageField(verbose_name=_('Photo'), upload_to='event_photos') + thumbnail = ImageSpecField(source='src', + processors=[ResizeToFill(250, 187)], + format='JPEG', + options={'quality': 60}) diff --git a/get_together/templates/get_together/events/add_photo.html b/get_together/templates/get_together/events/add_photo.html new file mode 100644 index 0000000..847e974 --- /dev/null +++ b/get_together/templates/get_together/events/add_photo.html @@ -0,0 +1,14 @@ +{% extends "get_together/base.html" %} + +{% block content %} +
{{photo.title}}
+