Django Library Themes
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

models.py 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from django.db import models
  2. from . import available_themes, default_theme
  3. from PIL import Image
  4. class Setting(models.Model):
  5. page_image = models.ImageField(
  6. upload_to='theme',
  7. default='theme/logo.png'
  8. )
  9. page_theme = models.CharField(
  10. max_length=64,
  11. choices=available_themes,
  12. default=default_theme
  13. )
  14. page_title = models.CharField(max_length=32, default='MyApp', blank=True)
  15. def save(self, *args, **kwargs):
  16. super().save(*args, **kwargs)
  17. img = Image.open(self.page_image.path)
  18. if img.height > 50:
  19. output_size = (int(img.width * 50 / img.height), 50)
  20. img.thumbnail(output_size)
  21. img.save(self.page_image.path)
  22. class BottomBar(models.Model):
  23. name = models.CharField(max_length=64, blank=True)
  24. icon = models.ImageField(upload_to='theme', blank=True)
  25. url = models.URLField()
  26. left = models.BooleanField()
  27. sequence_number = models.SmallIntegerField(choices=[(1, '1'), (2, '2'), (3, '3'), (4, '4'), (5, '5')])
  28. def save(self, *args, **kwargs):
  29. super().save(*args, **kwargs)
  30. if self.icon:
  31. img = Image.open(self.icon.path)
  32. if img.height > 40:
  33. output_size = (int(img.width * 40 / img.height), 40)
  34. img.thumbnail(output_size)
  35. img.save(self.icon.path)