123456789101112131415161718192021222324252627282930313233343536373839404142 |
- from django.db import models
- from . import available_themes, default_theme
- from PIL import Image
-
-
- class Setting(models.Model):
- page_image = models.ImageField(
- upload_to='theme',
- default='theme/logo.png'
- )
- page_theme = models.CharField(
- max_length=64,
- choices=available_themes,
- default=default_theme
- )
- page_title = models.CharField(max_length=32, default='MyApp', blank=True)
-
- def save(self, *args, **kwargs):
- super().save(*args, **kwargs)
-
- img = Image.open(self.page_image.path)
- if img.height > 50:
- output_size = (int(img.width * 50 / img.height), 50)
- img.thumbnail(output_size)
- img.save(self.page_image.path)
-
-
- class BottomBar(models.Model):
- name = models.CharField(max_length=64, blank=True)
- icon = models.ImageField(upload_to='theme', blank=True)
- url = models.URLField()
- left = models.BooleanField()
- sequence_number = models.SmallIntegerField(choices=[(1, '1'), (2, '2'), (3, '3'), (4, '4'), (5, '5')])
-
- def save(self, *args, **kwargs):
- super().save(*args, **kwargs)
- if self.icon:
- img = Image.open(self.icon.path)
- if img.height > 40:
- output_size = (int(img.width * 40 / img.height), 40)
- img.thumbnail(output_size)
- img.save(self.icon.path)
|