class Works(models.Model): name = models.CharField(max_length=200, verbose_name=u"Название") descriptions = models.TextField(max_length=500, verbose_name=u"Описание") mainPic = models.ImageField(upload_to='mPic', height_field=None, width_field=None, max_length=100, verbose_name=u"Главная картинка", default='default-image.jpg') mainCompressPic = ImageSpecField(source='mainPic', format='JPEG', options={'quality': 90}, processors=[ Adjust(contrast=1.2, sharpness=1.1), ResizeToFill(389, 380) ]) webMainCompressPic = ImageSpecField(source='mainPic', format='WEBP', options={'quality': 90}, processors=[ Adjust(contrast=1.2, sharpness=1.1), ResizeToFill(389, 380) ]) class Meta: verbose_name = u"Работа" verbose_name_plural = u"Работы" def __str__(self): return self.name
class Image(models.Model): SIZE_TYPES = ( (1, '600x600'), (2, '700x700'), (3, '800x800'), (4, '900x900'), (5, '1000x1000'), ) imag = models.ImageField(verbose_name='Изображение') size_type = models.IntegerField(verbose_name = 'Выберите размер для ресайза изображения', choices = SIZE_TYPES, default = '1') imag_one =ImageSpecField([Adjust(contrast=1.2, sharpness=1.1), ResizeToFit(600,600)], source='imag', options={'quality': 90}) imag_two =ImageSpecField([Adjust(contrast=1.2, sharpness=1.1), ResizeToFit(700, 700)], source='imag', options={'quality': 90}) imag_three =ImageSpecField([Adjust(contrast=1.2, sharpness=1.1), ResizeToFit(800, 800)], source='imag',options={'quality': 90}) imag_four =ImageSpecField([Adjust(contrast=1.2, sharpness=1.1), ResizeToFit(900, 900)], source='imag', options={'quality': 90}) imag_five =ImageSpecField([Adjust(contrast=1.2, sharpness=1.1), ResizeToFit(1000, 1000)], source='imag', options={'quality': 90}) User = get_user_model() user = models.ForeignKey(User, verbose_name='User', on_delete=models.CASCADE)
class PortfImage(models.Model): def get_file_path(self, filename): extension = filename.split('.')[-1] filename = '%s.%s' % (uuid.uuid4(), extension) return os.path.join('images', filename) record = models.ForeignKey(PortfRecord, related_name='images', blank=True) image = models.ImageField(upload_to=get_file_path, max_length=256) name = models.CharField(max_length=60) image_small = ImageSpecField( [Adjust(contrast=1.2, sharpness=1.1), ResizeToFill(120, 120)], image_field='image', format='JPEG', options={'quality': 90}) image_medium = ImageSpecField( [Adjust(contrast=1.2, sharpness=1.1), ResizeToFit(260, 260)], image_field='image', format='JPEG', options={'quality': 90}) image_big = ImageSpecField( [Adjust(contrast=1.2, sharpness=1.1), ResizeToFit(640, 480)], image_field='image', format='JPEG', options={'quality': 90}) '''image(s) to portfolio''' def __unicode__(self): return self.name
def get_file_path(self, filename): extension = filename.split('.')[-1] filename = "%s.%s" % (uuid.uuid4(), extension) return os.path.join("images", filename) photo = models.ImageField(verbose_name=u'Poster', upload_to=get_file_path, max_length=256, blank=True, null=True) photo_small = ImageSpecField( [Adjust(contrast=1.2, sharpness=1.1), ResizeToFill(50, 50)], image_field='photo', format='JPEG', options={'quality': 90}) photo_medium = ImageSpecField( [Adjust(contrast=1.2, sharpness=1.1), ResizeToFit(300, 200)], image_field='photo', format='JPEG', options={'quality': 90}) photo_big = ImageSpecField( [Adjust(contrast=1.2, sharpness=1.1), ResizeToFit(640, 480)], image_field='photo', format='JPEG', options={'quality': 90})
class CarouselInner(models.Model): service = models.ForeignKey( Services, on_delete=models.CASCADE, verbose_name='Услуга',) title = models.CharField(max_length=30, verbose_name='Заголовок',) text = models.CharField(max_length=500, blank=True, null=True, verbose_name='Текст',) img = models.ImageField(upload_to='setting', verbose_name='Изображение',) img_mobile = ImageSpecField(source='img', processors=[ Adjust(contrast=1.2, sharpness=1.2), ResizeToFill(800, 800)], format='JPEG', options={'quality': 90} ) img_desktop = ImageSpecField(source='img', processors=[ Adjust(contrast=1.2, sharpness=1.2), ResizeToFill(1920, 1080)], format='JPEG', options={'quality': 90} ) def image_img(self): if self.img: return mark_safe(u'<div align="center"><img src="{0}" height="40"/></a></div>'.format(self.img.url)) else: return 'Пиктограмма отсутствует.' image_img.short_description = ' ' class Meta: verbose_name_plural = "Вкладки карусели" verbose_name = "Вкладка" def __str__(self): return self.title
class NomadPost(Post): summary = models.TextField() image = models.ImageField(upload_to="images/posts/%Y/%m/%d", max_length=500, blank=True) # Imagekit specs pic = ImageSpecField( [Adjust(contrast=1.2, sharpness=1.1), ResizeToFit(720)], source='image', format='PNG', options={'quality': 90}) listed_pic = ImageSpecField( [Adjust(contrast=1.2, sharpness=1.1), ResizeToFill(720, 300)], source='image', format='PNG', options={'quality': 90}) def __unicode__(self): return self.title def get_absolute_url(self): # URLconf for non-country blog configurations category = self.categories.latest('id') return reverse('post_detail', kwargs={ 'category_slug': category.slug, 'slug': self.slug })
class FotoAgenciado(models.Model): agenciado = models.ForeignKey(Agenciado) foto = models.ImageField( verbose_name=ugettext_lazy(u'Foto (tamaño < %s MB)') % MAX_FOTO_SIZE, upload_to='agenciados/fotos/', blank=True, validators=[validate_image]) thumbnail = ImageSpecField( [Adjust(contrast=1.2, sharpness=1.1), ResizeToFill(100, 100)], source='foto', format='JPEG', options={'quality': 90}) mini_thumbnail = ImageSpecField( [Adjust(contrast=1.2, sharpness=1.1), ResizeToFill(60, 60)], source='foto', format='JPEG', options={'quality': 90}) def __str__(self): return self.foto.url class Meta: verbose_name = ugettext_lazy(u"Foto agenciado") verbose_name_plural = ugettext_lazy(u"Fotos agenciado")
class Survey(models.Model): photo_original = models.ImageField(upload_to='photos') photo_display = ImageSpecField( [Adjust(contrast=1.2, sharpness=1.1), ResizeToFill(400)], image_field='photo_original', format='JPEG', options={'quality': 90}) photo_thumbnail = ImageSpecField( [Adjust(contrast=1.2, sharpness=1.1), ResizeToFill(90)], image_field='photo_original', format='JPEG', options={'quality': 90}, ) video = models.FileField(upload_to='videos') user = models.ForeignKey(User) created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) def thumbnail(self): return """<img border="0" alt="" src= "/static/media/%s" height="40" /> """ % ( self.photo_original.name) thumbnail.allow_tags = True
class WallItem(models.Model): """ A simple note to post on a shared wall. """ wall = models.ForeignKey('Wall') author = models.ForeignKey(User, related_name="wall_item_author") body = models.TextField(_('item_body'), help_text='Use the editor to add links; no embedded html allowed.') created_at = models.DateTimeField(_('created at'), default=datetime.now) deleted = models.BooleanField(default=False) item_pic = models.ImageField(upload_to='upload',null=True,) item_pic_800x600 = ImageSpec([Adjust(contrast=1.2, sharpness=1.1), resize.Fit(800,600, False)], image_field='item_pic', format='JPEG', options={'quality': 90}) item_pic_resized = ImageSpec([Adjust(contrast=1.2, sharpness=1.1), resize.Fit(300, 300)], image_field='item_pic', format='JPEG', options={'quality': 90}) class Meta: verbose_name = _('wallitem') verbose_name_plural = _('wallitems') ordering = ('-created_at',) get_latest_by = 'created_at' def deleteable_by(self, user): return user == self.author or user.is_superuser def active_comments_set(self): return WallComment.objects.filter(wallitem=self, deleted=False) def __unicode__(self): return 'wall item created by %s on %s ( %s )' % ( self.author.username, self.created_at, truncatewords(self.body, 9 ))
class Recipe(models.Model): name = models.CharField(verbose_name='Название рецепта', max_length=256) author = models.ForeignKey( User, on_delete=models.CASCADE, related_name='recipes', ) description = models.TextField(verbose_name='Описание') image = models.ImageField(verbose_name='Картинка', upload_to='recipes/') image_max_size = ImageSpecField( [Adjust(contrast=1.2, sharpness=1.1), ResizeToFill(480, 480)], source='image', format='JPEG', options={'quality': 90}) image_med_size = ImageSpecField( [Adjust(contrast=1.2, sharpness=1.1), ResizeToFill(363, 363)], source='image', format='JPEG', options={'quality': 90}) image_small_size = ImageSpecField( [Adjust(contrast=1.2, sharpness=1.1), ResizeToFill(90, 90)], source='image', format='JPEG', options={'quality': 90}) cooking_time = NonZeroPositiveSmallIntegerField( verbose_name='Время готовки', ) pub_date = models.DateTimeField( verbose_name='Дата публикации', auto_now_add=True, ) slug = models.SlugField( verbose_name='SLUG-ссылка', null=True, blank=True, unique=True, ) objects = RecipeManager() tags = TaggableManager(manager=_CustomTaggableManager) class Meta: ordering = ['-pub_date'] def __str__(self): return self.name def save(self, *args, **kwargs): if not self.slug: self.slug = slugify(f'{self.name}') return super().save(*args, **kwargs) def get_absolute_url(self): return reverse('recipe', args=(self.id, self.slug)) def update_slug(self): self.slug = slugify(f'{self.name}')
class ImageMessage(models.Model): letter = models.ForeignKey(Message, on_delete = models.CASCADE) image = models.ImageField(upload_to="images/", null = True, blank = True) image_small = ImageSpecField([Adjust(contrast = 1, sharpness = 1), ResizeToFill(100, 100)], format = 'JPEG', options = {'quality' : 75}) image_ultra = ImageSpecField([Adjust(contrast = 1, sharpness = 1), ResizeToFill(50, 50)], format = 'JPEG', options = {'quality' : 50}) def __str__(self): return self.letter.writer.username
class Profile(ProfileBase): name = models.CharField( _("Display name"), max_length=50, null=True, blank=True, help_text='This will be shown to others when you use the site') about = models.TextField( _("About"), null=True, blank=True, help_text='Tell others about yourself, your gear, or your ride') profile_pic = models.ImageField( upload_to='upload', null=True, help_text="A picture of yourself, your bike, or something else") profile_pic_med = ImageSpec( [Adjust(contrast=1.2, sharpness=1.1), resize.Crop(80, 80)], image_field='profile_pic', format='JPEG', options={'quality': 90}) profile_pic_small = ImageSpec( [Adjust(contrast=1.2, sharpness=1.1), resize.Crop(40, 40)], image_field='profile_pic', format='JPEG', options={'quality': 90}) profile_pic_small_border = ImageSpec( [Adjust(contrast=1.2, sharpness=1.1), resize.Crop(40, 40), Border()], image_field='profile_pic', format='JPEG', options={'quality': 90}) #TODO use postgis? location = models.ForeignKey(Location, null=True, blank=True) days_per_week = models.DecimalField( "How many days per week do you commute by bike?", max_digits=1, decimal_places=0, choices=DAYS_PER_WEEK_CHOICES, null=True, blank=True) oneway_dist = models.DecimalField("How many miles is your one-way commute", max_digits=4, decimal_places=2, null=True, blank=True) oneway_time = models.DecimalField( "How many minutes does your one-way commute typically take?", max_digits=3, decimal_places=0, null=True, blank=True)
class Photo(models.Model): """Photo model""" LICENSES = ( ('http://creativecommons.org/licenses/by/2.0/', 'CC Attribution'), ('http://creativecommons.org/licenses/by-nd/2.0/', 'CC Attribution-NoDerivs'), ('http://creativecommons.org/licenses/by-nc-nd/2.0/', 'CC Attribution-NonCommercial-NoDerivs'), ('http://creativecommons.org/licenses/by-nc/2.0/', 'CC Attribution-NonCommercial'), ('http://creativecommons.org/licenses/by-nc-sa/2.0/', 'CC Attribution-NonCommercial-ShareAlike'), ('http://creativecommons.org/licenses/by-sa/2.0/', 'CC Attribution-ShareAlike'), ) title = models.CharField(max_length=255) slug = models.SlugField() photo = models.ImageField(upload_to="photos") photo_thumbnail = ImageSpecField(source='photo', processors=[ResizeToFit(460),Adjust(color=1.1)], format='JPEG', options={'quality': 75}) photo_admin_thumbnail = ImageSpecField(source='photo', processors=[ResizeToFit(100),Adjust(color=1.1)], format='JPEG', options={'quality': 60}) #photo_display = ImageSpecField(source='photo', # processors=[ResizeToFit(1024)], # format='JPEG', # options={'quality': 90}) taken_by = models.CharField(max_length=100, blank=True) license = models.URLField(blank=True, choices=LICENSES) description = models.TextField(blank=True) tags = TagField() uploaded = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) _exif = models.TextField(blank=True) class Meta: db_table = 'media_photos' def _set_exif(self, d): self._exif = simplejson.dumps(d) def _get_exif(self): if self._exif: return simplejson.loads(self._exif) else: return {} exif = property(_get_exif, _set_exif, "Photo EXIF data, as a dict.") def __unicode__(self): return '%s' % self.title @property def url(self): return '%s%s' % (settings.MEDIA_URL, self.photo) @permalink def get_absolute_url(self): return ('photo_detail', None, { 'slug': self.slug })
class Organization(models.Model): name = models.CharField(max_length=256, null=False, blank=False) slug = models.CharField(max_length=256, null=False, blank=False) site = models.ForeignKey(Site, on_delete=models.CASCADE) owner_profile = models.ForeignKey( UserProfile, related_name="owned_orgs", blank=False, null=True, on_delete=models.SET_NULL, ) cover_img = models.ImageField(verbose_name=_("Cover Image"), upload_to="org_covers", null=True, blank=True) tile_img = ImageSpecField( source="cover_img", processors=[Adjust(contrast=0.8, color=1), ResizeToFill(338, 200)], format="PNG", ) banner_img = ImageSpecField( source="cover_img", processors=[Adjust(contrast=0.8, color=1), ResizeToFill(825, 200)], format="PNG", ) description = models.TextField(blank=True, null=True) def save(self, *args, **kwargs): if not self.slug: new_slug = slugify(self.name) slug_matches = list(Organization.objects.filter(slug=new_slug)) if len(slug_matches) == 0 or (len(slug_matches) == 1 and slug_matches[0].id == self.id): self.slug = new_slug else: self.slug = "%s-%s" % (new_slug, self.id) super().save(*args, **kwargs) # Call the "real" save() method. def get_absolute_url(self): return reverse("show-org", kwargs={"org_slug": self.slug}) def __str__(self): return u"%s" % (self.name)
class Photo(models.Model): original_image = models.ImageField(upload_to='photos') thumbnail = ImageSpec([Adjust(contrast=1.2, sharpness=1.1), Crop(50, 50)], image_field='original_image', format='JPEG', options={'quality': 90}) smartcropped_thumbnail = ImageSpec( [Adjust(contrast=1.2, sharpness=1.1), SmartCrop(50, 50)], image_field='original_image', format='JPEG', options={'quality': 90})
def __init__(self, source): self.processors = [ Transpose(), ResizeToFill(self.size, self.size, upscale=self.upscale), Adjust(sharpness=2.0), ] super().__init__(source)
class ImagePost(models.Model): post = models.ForeignKey(Post, on_delete=models.CASCADE) image = models.ImageField(upload_to="images/") image_small = ImageSpecField( [Adjust(contrast=1, sharpness=1), ResizeToFill(100, 100)], format='JPEG', options={'quality': 75}) image_ultra = ImageSpecField( [Adjust(contrast=1, sharpness=1), ResizeToFill(50, 50)], format='JPEG', options={'quality': 50}) def __str__(self): return self.post.author.username
class Productos(models.Model): idproducto = models.IntegerField( db_column='idProducto', primary_key=True) # Field name made lowercase. nombreproducto = models.CharField( db_column='NombreProducto', unique=True, max_length=45) # Field name made lowercase. cantidadporunidad = models.IntegerField( db_column='CantidadPorUnidad') # Field name made lowercase. preciounidad = models.FloatField( db_column='PrecioUnidad') # Field name made lowercase. unidadesenexistencia = models.IntegerField( db_column='UnidadesEnExistencia') # Field name made lowercase. unidadesenpedido = models.IntegerField( db_column='UnidadesEnPedido') # Field name made lowercase. demanda_nivel = ( ('b', 'Bajo'), ('m', 'Medio'), ('a', 'Alto'), ) demanda = models.CharField( db_column='Demanda', max_length=1, choices=demanda_nivel) # Field name made lowercase. es_suspendido = ( ('s', 'Sí'), ('n', 'No'), ) suspendido = models.CharField( db_column='Suspendido', max_length=1, choices=es_suspendido) # Field name made lowercase. idproveedor = models.ForeignKey( Proveedores, models.PROTECT, db_column='IdProveedor') # Field name made lowercase. idcategoria = models.ForeignKey( Categorias, models.PROTECT, db_column='idCategoria') # Field name made lowercase. imagen = models.CharField(db_column='Imagen', unique=True, max_length=45) # Field name made lowercase. imagentest = models.ImageField(upload_to='img_prod', null=True, blank=True) thumbnail = ImageSpecField( [Adjust(contrast=1.2, sharpness=1.1), ResizeToFill(50, 50)], source='imagentest', format='JPEG', options={'quality': 90}) def __str__(self): return self.nombreproducto def get_absolute_url(self): """ Devuelve el URL a una instancia particular de Productos """ return reverse('product-detail', args=[str(self.idproducto)]) class Meta: #managed = False db_table = 'Productos'
class DidRecipe(models.Model): """docstring for DidRecipe""" recipe = models.ForeignKey(Recipe) user = models.ForeignKey(User) image = ProcessedImageField(upload_to=did_get_file_path, null=True, blank=True, verbose_name=u'Cover image', processors=[ Adjust(contrast=1.2, sharpness=1.1), ResizeToFit(width=540, upscale=True) ], format='JPEG', options={'quality': 90}) comment = models.TextField() date = models.DateTimeField(auto_now_add=True) def __unicode__(self): return u"%s's %s" % (self.user.username, self.recipe.name) @models.permalink def get_absolute_url(self): return ('did_recipe_detail', (), {'pk': self.id}) class Meta: ordering = ['recipe', '-date']
class Photo(models.Model): original_image = models.ImageField(upload_to='photos') # Implicit source field thumbnail = ImageSpecField( [Adjust(contrast=1.2, sharpness=1.1), ResizeToFill(50, 50)], format='JPEG', options={'quality': 90}) smartcropped_thumbnail = ImageSpecField( [Adjust(contrast=1.2, sharpness=1.1), SmartCrop(50, 50)], source='original_image', format='JPEG', options={'quality': 90})
class GalleryCoverJumbotron(ImageSpec): processors = [ ResizeToFill(940, 400), Adjust(contrast=1.2, sharpness=2), ] format = 'JPEG' options = {'quality': 80}
class Photo(models.Model): original_image = models.ImageField(upload_to='photos') thumbnail = ImageSpec([Adjust(contrast=1.2, sharpness=1.1), Crop(50, 50)], image_field='original_image', format='JPEG', quality=90)
class Recipe(models.Model): """docstring for Recipe""" name = models.CharField(db_index=True, max_length=200) author = models.ForeignKey(User) date = models.DateField(auto_now_add=True) category = models.ManyToManyField(RecipeCategory, verbose_name=u'list of categories') brief = models.TextField() ingredients = models.ManyToManyField(Food, through='Amount', verbose_name=u"list of ingredients") cover_image = ProcessedImageField(upload_to=get_file_path, null=True, blank=True, verbose_name=u'Cover image', processors=[ Adjust(contrast=1.2, sharpness=1.1), ResizeToFit(width=540, upscale=True) ], format='JPEG', options={'quality': 90}) tips = models.TextField(blank=True) did_num = models.PositiveIntegerField(default=0) like_num = models.PositiveIntegerField(default=0) view_num = models.PositiveIntegerField(default=0) trend_num = models.FloatField(default=0.0) today_view_num = models.PositiveIntegerField(default=0) prep_time = models.TimeField() cook_time = models.TimeField() cumulative_score = models.IntegerField(default=0) rating_num = models.IntegerField(default=0) def rating(self): result = float(self.cumulative_score) if self.rating_num == 0: return "0.0" result = result / self.rating_num return "%g" % round(result, 1) def rating_int(self): result = float(self.cumulative_score) if self.rating_num == 0: return 0 result = result / self.rating_num return int(round(result)) def __unicode__(self): return self.name @models.permalink def get_absolute_url(self): return ('recipe_detail', (), {'pk': self.id}) class Meta: ordering = ['-view_num', '-like_num']
def __init__(self, source): self.processors = [ Transpose(), ResizeToFill(self.width, self.height, upscale=True), Adjust(sharpness=2.0), ] super().__init__(source)
class PhotoGallery(models.Model): title = models.CharField(verbose_name='Название фото', max_length=100, db_index=True) created = models.DateField(verbose_name='Дата добавления фото', auto_now_add=True) photo = models.ImageField(verbose_name='Фото', upload_to='Main/PhotoGallery', height_field=None, width_field=None, max_length=256, blank=True, null=True) photo_s = ImageSpecField([Adjust(contrast=1.0, sharpness=1.0), ResizeToFill(350, 170)], source='photo', format='JPEG', options={'quality': 100}) descriptions = models.TextField(verbose_name='Описание фото', null=True, blank=True) album = models.ForeignKey(PhotoAlbums, verbose_name='Альбом', null=True, blank=True, on_delete=models.CASCADE) class Meta: verbose_name = "Фотография" verbose_name_plural = "Фотографии" ordering = ["-id"] def save(self, *args, **kwargs): super().save(*args, **kwargs) def __str__(self): return self.title
class UserProfile(models.Model): user = models.OneToOneField(User) avatar = models.ImageField(upload_to=img_url, blank=True, null=True) avatar_small = ImageSpecField( [Adjust(contrast=1.2, sharpness=1.1), ResizeToFill(40, 40)], format='JPEG', options={'quality': 90}) avatar_medium = ImageSpecField( [Adjust(contrast=1.2, sharpness=1.1), ResizeToFill(70, 70)], format='JPEG', options={'quality': 90}) def __str__(self): return self.user.username
class Pictures(models.Model): work = models.ForeignKey(Works, related_name='picture', on_delete=models.CASCADE, verbose_name=u"Картинкы") pic = models.ImageField(upload_to='pic', height_field=None, width_field=None, max_length=100, verbose_name=u"Картинка") compressPic = ImageSpecField(source='pic', format='JPEG', options={'quality': 90}, processors=[ Adjust(contrast=1.2, sharpness=1.1), ResizeToFit(1000, 1000) ]) mobileCompressPic = ImageSpecField(source='pic', format='JPEG', options={'quality': 90}, processors=[ Adjust(contrast=1.2, sharpness=1.1), ResizeToFit(600, 600) ]) webPic = ImageSpecField(source='pic', format='WEBP', options={'quality': 90}, processors=[ Adjust(contrast=1.2, sharpness=1.1), ResizeToFit(1000, 1000) ]) mobileWebPic = ImageSpecField(source='pic', format='WEBP', options={'quality': 90}, processors=[ Adjust(contrast=1.2, sharpness=1.1), ResizeToFit(600, 600) ]) class Meta: verbose_name = u"Картина" verbose_name_plural = u"Картины"
class Recipe(GrapheneFieldsMixin, models.Model): name = models.CharField(max_length=50) slug = models.SlugField(unique=True, blank=True, null=True) image = models.ImageField(blank=True, null=True, upload_to='images') image_top = ImageSpecField(source='image', processors=[SmartResize(1000, 400)], format='JPEG', options={'quality': 60}) image_thumbnail = ImageSpecField( source='image', processors=[ResizeToFit(330, 220), Adjust(sharpness=1.1)], format='JPEG', options={'quality': 60}) body = HTMLField() tags = models.ManyToManyField(Tag, related_name='recipes', blank=True) favourites = models.ManyToManyField(User, related_name='favoured', blank=True) DIFFICULTY_CHOICES = ( ('easy', 'Easy'), ('medium', 'Normal'), ('hard', 'Hard'), ) difficulty = models.CharField(max_length=6, choices=DIFFICULTY_CHOICES, default='medium', blank=True, null=True) time_need = models.SmallIntegerField(null=True, blank=True) portions = models.SmallIntegerField(null=True, blank=True) description = HTMLField(null=True, blank=True) created_at = models.DateTimeField(auto_now_add=True) def __str__(self): return self.name def save(self, *args, **kwargs): self.slug = slugify(self.name) super(Recipe, self).save(*args, **kwargs) def set_favourite(self, user, state_to_set): if not state_to_set: current_state = self.favourites.filter(pk=user.pk).exists() state_to_set = not current_state if state_to_set: self.favourites.add(user) else: self.favourites.remove(user) return True
def __init__(self, source, width=420, height=595): self.source = source self.processors = [ Adjust(contrast=1.1, sharpness=1.1), SmartResize(width, height) ] self.format = 'JPEG' self.options = {'quality': 90}
class Avatar(models.Model): avatar = models.ImageField(upload_to='users', default='users/default.jpg') avatar_small = ImageSpecField( format='JPEG', source='avatar', processors=[Adjust(contrast=1.2, sharpness=1.1), ResizeToFill(40, 40)], options={'quality': 90}) avatar_medium = ImageSpecField(format='JPEG', source='avatar', processors=[ Adjust(contrast=1.2, sharpness=1.1), ResizeToFill(250, 250) ], options={'quality': 90}) avatar_large = ImageSpecField(format='JPEG', source='avatar', processors=[ResizeToFill(500, 500)], options={'quality': 100}) date_uploaded = models.DateField(default=timezone.now)