Added ProjectImage and refactored migrations. Now project have
galleries :D
This commit is contained in:
parent
ff20cc9f23
commit
5373454b12
|
@ -7,3 +7,4 @@ bower_components
|
|||
*.sublime-workspace
|
||||
.sass-cache
|
||||
db.sqlite3
|
||||
projects/
|
||||
|
|
|
@ -32,8 +32,13 @@ admin.site.register(models.Group, GroupAdmin)
|
|||
#
|
||||
# Project
|
||||
#
|
||||
class ProjectImageInline(admin.TabularInline):
|
||||
model = models.ProjectImage
|
||||
|
||||
|
||||
class ProjectAdmin(reversion.VersionAdmin):
|
||||
list_display = ('title', 'group', 'company', 'role', )
|
||||
inlines = (ProjectImageInline, )
|
||||
|
||||
prepopulated_fields = {"slug": ("title",)}
|
||||
|
||||
|
|
|
@ -29,7 +29,6 @@ class Migration(migrations.Migration):
|
|||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('title', models.CharField(max_length=128)),
|
||||
('image', models.ImageField(default=None, upload_to=fmartingrcom.apps.projects.models.project_upload_to)),
|
||||
('slug', models.SlugField(max_length=128)),
|
||||
('date', models.DateTimeField()),
|
||||
('company', models.CharField(max_length=128, null=True, blank=True)),
|
||||
|
@ -45,4 +44,15 @@ class Migration(migrations.Migration):
|
|||
},
|
||||
bases=(models.Model,),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='ProjectImage',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('image', models.ImageField(upload_to=fmartingrcom.apps.projects.models.project_image_upload_to)),
|
||||
('project', models.ForeignKey(related_name='images', to='projects.Project')),
|
||||
],
|
||||
options={
|
||||
},
|
||||
bases=(models.Model,),
|
||||
),
|
||||
]
|
||||
|
|
|
@ -2,9 +2,12 @@
|
|||
|
||||
# python
|
||||
import os
|
||||
import random
|
||||
import string
|
||||
|
||||
# django
|
||||
from django.db import models
|
||||
from django.conf import settings
|
||||
|
||||
# 3rd party
|
||||
from ckeditor.fields import RichTextField
|
||||
|
@ -22,15 +25,9 @@ class Group(models.Model):
|
|||
return self.name
|
||||
|
||||
|
||||
def project_upload_to(ins, filename):
|
||||
name, ext = os.path.splitext(filename)
|
||||
return 'projects/{}{}'.format(ins.slug, ext)
|
||||
|
||||
|
||||
class Project(models.Model):
|
||||
group = models.ForeignKey(Group, related_name='projects')
|
||||
title = models.CharField(max_length=128)
|
||||
image = models.ImageField(upload_to=project_upload_to, default=None)
|
||||
slug = models.SlugField(max_length=128)
|
||||
date = models.DateTimeField()
|
||||
company = models.CharField(max_length=128, null=True, blank=True)
|
||||
|
@ -46,3 +43,17 @@ class Project(models.Model):
|
|||
|
||||
class Meta:
|
||||
ordering = ['-date']
|
||||
|
||||
|
||||
def random_string(size=6, chars=string.ascii_lowercase + string.digits):
|
||||
return ''.join(random.choice(chars) for _ in range(size))
|
||||
|
||||
|
||||
def project_image_upload_to(ins, filename):
|
||||
name, ext = os.path.splitext(filename)
|
||||
return 'projects/{}_{}{}'.format(ins.project.slug, random_string(), ext)
|
||||
|
||||
|
||||
class ProjectImage(models.Model):
|
||||
project = models.ForeignKey(Project, related_name='images')
|
||||
image = models.ImageField(upload_to=project_image_upload_to)
|
||||
|
|
|
@ -45,8 +45,11 @@ INSTALLED_APPS = (
|
|||
'fmartingrcom.apps.projects',
|
||||
|
||||
'django_jinja',
|
||||
'django_jinja.contrib._easy_thumbnails',
|
||||
|
||||
'ckeditor',
|
||||
|
||||
'easy_thumbnails',
|
||||
)
|
||||
|
||||
|
||||
|
@ -118,6 +121,12 @@ COMPRESS_PRECOMPILERS = (
|
|||
('text/coffeescript', 'coffee --compile --stdio --no-header'),
|
||||
)
|
||||
|
||||
THUMBNAIL_ALIASES = {
|
||||
'': {
|
||||
'project_thumb': {'size': (150, 150), 'crop': True},
|
||||
},
|
||||
}
|
||||
|
||||
#
|
||||
# MEDIA FILES
|
||||
#
|
||||
|
|
|
@ -50,7 +50,5 @@ body
|
|||
float: right
|
||||
.computer
|
||||
max-width: inherit
|
||||
.image
|
||||
max-width: inherit
|
||||
width: 90%
|
||||
margin-top: 3%
|
||||
.images a:hover
|
||||
text-decoration: none !important
|
||||
|
|
|
@ -29,8 +29,10 @@
|
|||
{% if project.url %}
|
||||
<h5 class="url"><i class="fa fa-link"></i> <a href="{{ project.url }}">{{ project.url }}</a></h5>
|
||||
{% endif %}
|
||||
<div class="text-center computer">
|
||||
<img class="image" src="{{ MEDIA_URL }}{{ project.image }}" />
|
||||
<div class="text-center images">
|
||||
{% for image in project.images.all() %}
|
||||
<a href="{{ MEDIA_URL }}{{ image.image }}" data-lightbox="{{ project.slug }}"><img src="{{ image.image|thumbnail_url('project_thumb') }}" /></a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<p class="description">{{ project.description|safe }}</p>
|
||||
</div>
|
||||
|
@ -43,13 +45,20 @@
|
|||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block stylesheets %}
|
||||
{{ super() }}
|
||||
<link href="{{ STATIC_URL }}bower/lightbox2/css/lightbox.css" rel="stylesheet" />
|
||||
{% endblock %}
|
||||
|
||||
{% block javascript %}
|
||||
{{ super() }}
|
||||
<script type="text/javascript" src="{{ STATIC_URL }}bower/jquery/dist/jquery.js"></script>
|
||||
<script type="text/javascript" src="{{ STATIC_URL }}bower/lightbox2/js/lightbox.js"></script>
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
$('[data-toggle-on-click]').click(function(event) {
|
||||
$(this).children('[data-viewmore]').slideToggle(300);
|
||||
if (!$(event.target).is('img'))
|
||||
$(this).children('[data-viewmore]').slideToggle(300);
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
|
|
@ -13,3 +13,5 @@ django-ckeditor-updated==4.4.4
|
|||
pytz==2014.10
|
||||
|
||||
django-compressor==1.4
|
||||
|
||||
easy-thumbnails==2.2
|
||||
|
|
Loading…
Reference in New Issue