Commit 89478fd1 authored by Florent Chehab's avatar Florent Chehab

versionning added to university model

parent 5b8d987e
......@@ -38,6 +38,8 @@ INSTALLED_APPS = [
'django.contrib.messages',
'django.contrib.staticfiles',
'django_cas_ng',
'reversion',
'reversion_compare',
'main_website',
'rex'
]
......
......@@ -4,3 +4,5 @@ django-cas-ng>=3.5.9
django-markdownx==2.0.22
Pillow==5.0.0
django-imagekit==4.0.2
django-reversion==2.0.13
django-reversion-compare==0.8.4
from django.contrib import admin
from .models.university import University
admin.site.register(University)
from reversion_compare.admin import CompareVersionAdmin
admin.site.register(University, CompareVersionAdmin)
# Generated by Django 2.0.3 on 2018-04-01 10:09
# Generated by Django 2.0.3 on 2018-04-01 13:43
from django.db import migrations, models
import django.utils.timezone
import uuid
import rex.utils.friendly_path
class Migration(migrations.Migration):
......@@ -14,13 +14,14 @@ class Migration(migrations.Migration):
operations = [
migrations.AddField(
model_name='university',
name='logo',
field=models.ImageField(default=django.utils.timezone.now, upload_to='uploads/<django.db.models.fields.UUIDField>'),
name='acronym',
field=models.CharField(default=django.utils.timezone.now, max_length=20),
preserve_default=False,
),
migrations.AlterField(
migrations.AddField(
model_name='university',
name='id',
field=models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False),
name='logo',
field=models.ImageField(default=django.utils.timezone.now, upload_to=rex.utils.friendly_path.friendly_path('uploads/universities/logos/', 'name')),
preserve_default=False,
),
]
# Generated by Django 2.0.3 on 2018-04-01 13:50
from django.db import migrations, models
import rex.utils.friendly_path
class Migration(migrations.Migration):
dependencies = [
('rex', '0003_auto_20180401_1543'),
]
operations = [
migrations.AlterField(
model_name='university',
name='logo',
field=models.ImageField(max_length=250, upload_to=rex.utils.friendly_path.friendly_path('uploads/universities/logos/', 'name')),
),
]
from django.db import models
import uuid
from rex.utils.friendly_path import friendly_path
path_and_rename = friendly_path("uploads/universities/logos/",'name')
class University(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
name = models.CharField(max_length=200)
acronym = models.CharField(max_length=20)
localization_lat = models.DecimalField(max_digits=10, decimal_places=6)
localization_lon = models.DecimalField(max_digits=10, decimal_places=6)
logo = models.ImageField(upload_to='uploads/'+str(id))
logo = models.ImageField(upload_to=path_and_rename, max_length=250)
def localization(self):
return {'lat':self.localization_lat, 'lon':self.localization_lon}
\ No newline at end of file
from django.conf import settings
from django.utils.deconstruct import deconstructible
import os
@deconstructible
class friendly_path(object):
def __init__(self, rel_path, attribute_distinction):
self.rel_path = rel_path
self.attr = attribute_distinction
def __call__(self, instance, filename):
ext = filename.split('.')[-1]
i = 0
while True:
filename = '{}_{}.{}'.format(getattr(instance, self.attr), str(i), ext)
path_and_fn = os.path.join(settings.MEDIA_ROOT, self.rel_path, filename)
if not os.path.isfile(path_and_fn):
break
i += 1
return os.path.join(self.rel_path, filename)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment