Ejemplo n.º 1
0
class Product(models.Model):
    english_title = models.CharField(max_length=200)
    persian_title = models.CharField(max_length=200)
    brand_name = models.CharField(max_length=200)
    price = models.DecimalField(decimal_places=0,
                                max_digits=30,
                                default=100000)
    quantity = models.PositiveIntegerField(default='1')
    slug = models.SlugField(max_length=250, blank=True, null=True)
    active = models.BooleanField(default=True)
    featured = models.BooleanField(default=False)
    image = models.ImageField(upload_to='products_pics', null=True, blank=True)
    date = models.CharField(max_length=200, default=shamsi_date)
    category = models.ForeignKey(Category,
                                 models.SET_NULL,
                                 null=True,
                                 blank=True)
    sub_category = models.ForeignKey(SubCategory,
                                     models.SET_NULL,
                                     null=True,
                                     blank=True)
    description = models.ForeignKey(StandardDescription,
                                    models.SET_NULL,
                                    null=True,
                                    blank=True)

    image_medium = ImageSpecField(source='image',
                                  processors=[Thumbnail(120, 120)],
                                  format='JPEG',
                                  options={'quality': 60})
    image_small = ImageSpecField(source='image',
                                 processors=[Thumbnail(50, 50)],
                                 format='JPEG',
                                 options={'quality': 60})

    #quantity caterody

    def __str__(self):
        return self.english_title

    def get_absolute_url(self):
        return reverse('products:detail', kwargs={'slug': self.slug})

    def persian_num(self):
        # i = 0
        # result = ''
        # for num in reversed(persian.convert_en_numbers(self.price)):
        #     print(num)
        #     if i == 2:
        #         result = num + ',' +result
        #     else:
        #         result = num + result
        #     i += 1

        return persian.convert_en_numbers(self.price)
Ejemplo n.º 2
0
class Post(models.Model):
    image = models.ImageField(upload_to='images')
    image_medium = ImageSpecField(source='image',
                                  processors=[Thumbnail(200, 100)],
                                  format='JPEG',
                                  options={'quality': 60})
    image_small = ImageSpecField(source='image',
                                 processors=[Thumbnail(100, 50)],
                                 format='JPEG',
                                 options={'quality': 60})
    slug = models.SlugField(max_length=255, unique=True)
    
Ejemplo n.º 3
0
class Picture(models.Model):
    product = models.ForeignKey(Product, on_delete=models.CASCADE)
    image = models.ImageField(upload_to='pictures_gallery')

    image_medium = ImageSpecField(source='image',
                                  processors=[Thumbnail(120, 120)],
                                  format='JPEG',
                                  options={'quality': 60})
    image_small = ImageSpecField(source='image',
                                 processors=[Thumbnail(50, 50)],
                                 format='JPEG',
                                 options={'quality': 60})

    def __str__(self):
        return self.product.english_title
Ejemplo n.º 4
0
    def generate_thumbnail(self, width, height, generate=True):
        """Generate a thumbnail for the given size.
        """
        self._require_thumbnail()
        self._require_file()
        path = self.get_thumbnail_path(width, height)
        if generate and not self.storage.exists(path):
            processor = Thumbnail(width=width, height=height, crop=False)
            try:
                fp = urllib.request.urlopen(self.url)
                img = io.BytesIO(fp.read())
            except ValueError:  # is in local
                img = self.path

            try:
                with PILImage.open(img) as image:
                    resized_image = processor.process(image)
                    save_pilimage(resized_image, path, self.storage)
            except IOError as e:
                logger.warning(e)
Ejemplo n.º 5
0
class Games(models.Model):
    image = models.ImageField(upload_to='images/', blank=True)
    image_medium = ImageSpecField(source='image',
                                  processors=[Thumbnail(160, 205)],
                                  format='JPEG',
                                  options={'quality': 60})
    image_latest_small = ImageSpecField(source='image',
                                        processors=[Thumbnail(160, 136)],
                                        format='JPEG',
                                        options={'quality': 60})
    image_latest = ImageSpecField(source='image',
                                  processors=[Thumbnail(700, 350)],
                                  format='JPEG',
                                  options={'quality': 60})
    image_detail = ImageSpecField(source='image',
                                  processors=[Thumbnail(400, 400)],
                                  format='JPEG',
                                  options={'quality': 60})
    title = models.CharField(max_length=30, unique=True)
    slug = models.SlugField(unique=True, blank=True)
    description = models.TextField()
    category = models.ForeignKey(Categories, on_delete=models.CASCADE)
    productor = models.CharField(max_length=30)
    date = models.DateField(auto_now=False, auto_now_add=False)
    price = models.DecimalField(max_digits=7, decimal_places=0)
    grade = models.IntegerField()
    plateform = models.ManyToManyField(Consoles,
                                       through='Counter',
                                       through_fields=('game', 'console'))

    def __str__(self):
        return self.title

    def save(self, *args, **kwargs):
        if not self.slug:
            self.slug = slugify(str(self.title) + "-" + str(self.date))
        super(Games, self).save(*args, **kwargs)

    class Meta:
        ordering = ['title']
Ejemplo n.º 6
0
class Photo(models.Model):
    user = models.ForeignKey('users.User',
                             related_name='photo_owners',
                             on_delete=models.CASCADE)
    post = models.ForeignKey('feeds.Post',
                             related_name='photo_posts',
                             on_delete=models.CASCADE)
    image_name = models.CharField(max_length=50)
    photo_images = models.ImageField(upload_to=upload_to)  # generate uuid path
    thumbnail_image = ImageSpecField(source='photo_images',
                                     processors=[Thumbnail(161, 161)],
                                     format='JPEG',
                                     options={'quality': 60})
Ejemplo n.º 7
0
class ProductThumbnailImage(models.Model):
    p_target_product_id = models.ForeignKey(Product,
                                            on_delete=models.CASCADE,
                                            related_name='product_thumbnails',
                                            verbose_name='p_target_product_id')
    p_thumbnail = ProcessedImageField(upload_to='product_thumbnails',
                                      processors=[
                                          Transpose(),
                                          Thumbnail(300, 300)],
                                      format='JPEG',
                                      options={'quality': 60}, null=True, blank=True)

    def __str__(self):
        return str(self.p_target_product_id)
Ejemplo n.º 8
0
class ListArticle(models.Model):
    id = models.AutoField(primary_key=True)
    text = models.TextField(blank=True, verbose_name=_('текст'))
    image = models.ImageField(upload_to="listArticles",
                              blank=True,
                              verbose_name=_('картинка'))
    image_thumbnail = ImageSpecField(source='image',
                                     processors=[Thumbnail(500, 300)],
                                     format='JPEG',
                                     options={'quality': 500})

    class Meta:
        verbose_name = _('новость')
        verbose_name_plural = _('новости')
Ejemplo n.º 9
0
class Picture(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.TextField(blank=True, verbose_name=_('имя'))
    image = models.ImageField(upload_to="main",
                              blank=True,
                              verbose_name=_('картинка'))
    image_thumbnail = ImageSpecField(source='image',
                                     processors=[Thumbnail(200, 100)],
                                     format='JPEG',
                                     options={'quality': 90})

    class Meta:
        verbose_name = _('картинка')
        verbose_name_plural = _('картинки')
Ejemplo n.º 10
0
class Post(models.Model):
    title = models.CharField(max_length=100)
    content = models.TextField()
    image = models.ImageField(upload_to='image',
                              default='default_post_image.jpg')
    date_posted = models.DateTimeField(default=timezone.now)
    author = models.ForeignKey(User, on_delete=models.CASCADE)
    categories = models.ManyToManyField(Category)

    image_medium = ImageSpecField(source='image',
                                  processors=[Thumbnail(200, 100)],
                                  format='JPEG',
                                  options={'quality': 60})

    image_small = ImageSpecField(source='image',
                                 processors=[Thumbnail(100, 50)],
                                 format='JPEG',
                                 options={'quality': 60})

    def __str__(self):
        return self.title

    def get_absolute_url(self):
        return reverse('blog:post-detail', kwargs={'pk': self.pk})
Ejemplo n.º 11
0
class Profile(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    first_name = models.CharField(max_length=20,
                                  null=True,
                                  blank=True,
                                  db_index=False)
    last_name = models.CharField(max_length=20,
                                 null=True,
                                 blank=True,
                                 db_index=False)
    #profile_pic = models.
    created = models.DateTimeField(auto_now_add=True)
    image = models.ImageField(upload_to='images', null=True, blank=True)
    thumbnail = ImageSpecField(source='image',
                               processors=[Thumbnail(128, 128)],
                               format='JPEG',
                               options={'quality': 60})
    email = models.EmailField(null=True)
Ejemplo n.º 12
0
def mkthum(image_source):
    processor = Thumbnail(width=300, height=200)
    mountain_image = Image.open(image_source)

    thumb_image = processor.process(mountain_image)
    thumb_image.save("thumbnail.png", quality=60)
Ejemplo n.º 13
0
class Article(models.Model):
    title = models.CharField(verbose_name="title",
                             max_length=150,
                             blank=False,
                             null=False)
    slug = models.SlugField(max_length=160,
                            blank=True,
                            null=False,
                            unique_for_date="published_at")
    author = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        verbose_name="author",
        blank=False,
        null=True,
        related_name="articles",
        on_delete=models.SET_NULL,
    )
    category = models.ForeignKey(
        Category,
        verbose_name="category",
        blank=False,
        null=True,
        on_delete=models.SET_NULL,
        related_name="articles",
    )
    image = models.ImageField(
        verbose_name="image",
        help_text="Article main image",
        blank=True,
        null=True,
        max_length=150,
        upload_to=article_image_upload_to,
    )
    description = models.TextField(verbose_name="description", max_length=600)
    content = models.TextField(verbose_name="content")
    is_featured = models.BooleanField(
        verbose_name="is featured",
        default=False,
        blank=True,
        help_text="Mark an article as a featured on home page",
    )
    is_category_featured = models.BooleanField(
        verbose_name="is category featured", default=False, blank=True)
    is_published = models.BooleanField(verbose_name="is published",
                                       blank=True,
                                       default=False)
    published_at = models.DateTimeField(verbose_name="published at",
                                        blank=True,
                                        null=True,
                                        default=None)
    comments_count = models.IntegerField(
        verbose_name="number of comments",
        blank=False,
        null=False,
        default=0,
        help_text=("Number of comments associated with this article. "
                   "Calculates automatically after posting each comment."),
    )
    created_at = models.DateTimeField(verbose_name="created at",
                                      auto_now_add=True)
    updated_at = models.DateTimeField(verbose_name="updated at", auto_now=True)

    objects = models.Manager()
    published = PublishedArticlesManager()

    image_100x100 = ImageSpecField(
        source="image",
        processors=[Thumbnail(100, 100, anchor="auto")],
        format="PNG")
    image_730x350 = ImageSpecField(
        source="image",
        processors=[SmartResize(730, 350)],
        format="JPEG",
        options={"quality": 90},
    )
    image_420x330 = ImageSpecField(
        source="image",
        processors=[SmartResize(420, 330)],
        format="JPEG",
        options={"quality": 90},
    )

    class Meta:
        verbose_name = "article"
        verbose_name_plural = "articles"

        indexes = (
            models.Index(fields=("-comments_count", )),
            models.Index(fields=("-created_at", )),
            models.Index(fields=("is_category_featured", )),
            models.Index(fields=("is_published", "-published_at")),
            models.Index(fields=("slug", "published_at")),
        )

    def __str__(self):
        return self.title

    def __repr__(self):
        return "<Article id={} title={} is_published={}>".format(
            self.pk, self.title, self.is_published)

    def get_absolute_url(self):
        return reverse("articles:detail", args=(self.pk, ))
Ejemplo n.º 14
0
class Rooms(models.Model):
    """
    Rooms Details 세부 사항,
    """

    ROOMS_TYPE_APARTMENT = 'AP'
    ROOMS_TYPE_HOUSING = 'HO'
    ROOMS_TYPE_ONEROOM = 'OR'
    ROOMS_TYPE_GUESTHOUSE = 'GH'

    ROOMS_TYPE = (
        (ROOMS_TYPE_APARTMENT, '아파트'),
        (ROOMS_TYPE_HOUSING, '주택'),
        (ROOMS_TYPE_ONEROOM, '원룸'),
        (ROOMS_TYPE_GUESTHOUSE, '게스트하우스'),
    )

    # 숙소 이름
    rooms_name = models.CharField(
        verbose_name='숙소 이름',
        help_text='숙소의 이름을 입력하세요',
        max_length=150,
    )

    # 태그
    rooms_tag = models.CharField(
        verbose_name='태그',
        help_text='검색에 사용될 지역 태그를 입력하세요',
        max_length=150,
        blank=True,
    )

    # 호스트
    rooms_host = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        verbose_name='호스트',
        help_text='숙소의 오너입니다.',
        on_delete=models.CASCADE,
        related_name='with_host_rooms',
    )

    # 숙소 커버 이미지
    rooms_cover_image = models.ImageField(
        upload_to='cover_image',
        verbose_name='숙소의 커버 이미지입니다.',
        max_length=255,
    )

    rooms_cover_thumbnail = ImageSpecField(
        source='rooms_cover_image',
        processors=[Thumbnail(308, 206)],
        format='png',
        options={'quality': 100},
    )

    # 일일 요금
    days_price = models.PositiveIntegerField(verbose_name='일일 숙박 요금',
                                             help_text='일일 숙박 요금을 입력하세요')

    # 숙소 설명
    rooms_description = models.TextField(
        verbose_name='숙소 개요',
        help_text='당신의 숙소를 소개하세요, 게스트의 흥미를 유발하는것이 중요합니다.',
        max_length=255,
    )

    # 객실 수
    rooms_amount = models.PositiveSmallIntegerField(
        verbose_name='객실 수', help_text='숙소 내의 객실 수를 입력하세요')

    # 침대 갯수
    rooms_bed = models.PositiveSmallIntegerField(verbose_name='침대 수',
                                                 help_text='객실 내의 침대 수를 입력하세요')

    # 숙박 인원
    rooms_personnel = models.PositiveSmallIntegerField(
        verbose_name='숙박 가능 인원', help_text='최대 숙박 가능인원을 입력하세요')

    # 욕실 갯수
    rooms_bathroom = models.PositiveSmallIntegerField(
        verbose_name='욕실 수', help_text='숙소 내의 욕실 수를 입력하세요')

    # 숙소 유형
    rooms_type = models.CharField(verbose_name='숙소 유형',
                                  help_text='숙소의 유형을 선택해주세요',
                                  choices=ROOMS_TYPE,
                                  max_length=2,
                                  default=ROOMS_TYPE_ONEROOM)

    # 체크인 최소
    check_in_minimum = models.PositiveSmallIntegerField(
        verbose_name='최소 숙박 가능일',
        help_text='최소 숙박 가능일 수를 입력해주세요',
        default=1,
    )

    # 체크인 최대
    check_in_maximum = models.PositiveSmallIntegerField(
        verbose_name='최대 숙박 가능일',
        help_text='최대 숙박 가능일 수를 입력해주세요',
        default=3,
        blank=True,
    )

    # 환불규정
    refund = models.TextField(verbose_name='환불 규정',
                              help_text='환불 규정을 가급적 상세히 입력해주세요',
                              blank=True,
                              default='''
                일반 정책 \n
                More information \n
                체크인 5일 전까지 예약을 취소하면 에어비앤비 서비스 수수료을 제외한 요금이 환불됩니다.\n
                체크인까지 5일이 남지 않은 시점에 예약을 취소하면 첫 1박 요금과 나머지 숙박 요금의 50%는 환불되지 않습니다. \n
                에어비앤비 서비스 수수료는 예약 후 48시간 이내에 취소하고 체크인 전인 경우에만 환불됩니다. \n
                ''')

    # 나라
    address_country = models.CharField(verbose_name='국가',
                                       max_length=50,
                                       blank=True)

    # 도시
    address_city = models.CharField(verbose_name='도시',
                                    max_length=100,
                                    blank=True)

    # 시/군/구
    address_district = models.CharField(verbose_name='시/군/구',
                                        max_length=150,
                                        blank=True)

    # 상세주소
    address_detail = models.CharField(verbose_name='상세 주소',
                                      max_length=150,
                                      blank=True)

    # 위도
    address_latitude = models.DecimalField(
        verbose_name='Google MAP API 위도',
        decimal_places=14,
        max_digits=16,
        blank=True,
    )

    # 경도
    address_longitude = models.DecimalField(
        verbose_name='Google MAP API 경도',
        decimal_places=14,
        max_digits=17,
        blank=True,
    )

    # 생성 일자 자동 저장
    created_at = models.DateTimeField(auto_now_add=True)

    # 수정 일자 자동 저장
    modified_date = models.DateTimeField(auto_now=True)

    def __str__(self):
        return f'{self.pk} {self.rooms_host} {self.rooms_name}'

    class Meta:
        ordering = ['-created_at']
Ejemplo n.º 15
0
class Post(ModelMeta, models.Model):
    title = models.CharField(max_length=200, unique=True)
    slug = models.SlugField(
        max_length=200,
        unique=True,
        allow_unicode=True,
        help_text=
        "The name of the page as it will appear in URLs e.g http://domain.com/blog/[my-slug]/"
    )
    image = models.ImageField(upload_to='Images/blog_thumbs',
                              default='Images/blog_thumbs/default.png',
                              blank=True)
    image_alt = models.CharField(max_length=200, blank=True)
    author = models.ForeignKey(User,
                               on_delete=models.CASCADE,
                               related_name='blog_posts')
    content = RichTextUploadingField()

    category = models.ManyToManyField(Category)
    tags = TaggableManager()
    created_date = models.DateTimeField(auto_now_add=True)
    updated_date = models.DateTimeField(auto_now=True)
    published_date = models.DateTimeField(blank=True, default=timezone.now)
    status = models.IntegerField(choices=STATUS, default=0)

    image_large = ImageSpecField(source='image',
                                 processors=[Thumbnail(750, 440)],
                                 format='JPEG',
                                 options={'quality': 60})
    image_medium = ImageSpecField(source='image',
                                  processors=[Thumbnail(200, 200)],
                                  format='JPEG',
                                  options={'quality': 60})
    image_small = ImageSpecField(source='image',
                                 processors=[Thumbnail(150, 150)],
                                 format='JPEG',
                                 options={'quality': 60})

    _metadata = {
        'title': 'title',
        'description': 'get_meta_content',
        'image': 'get_meta_image',
        'published_time': 'published_date',
        'modified_time': 'updated_date',
        'url': 'get_absolute_url',
        'locale': 'fa_IR',
        'keywords': 'get_meta_keywords'
    }

    def get_meta_content(self):
        value = strip_spaces_between_tags(self.content)
        value = value.replace("</p>", " </p>")
        value = value.replace("&quot", "  ")
        value = strip_tags(value)
        return Truncator(value).words(40)

    def get_meta_image(self):
        if self.image:
            return self.image.url

    class Meta:
        ordering = ['-created_date']

    def __str__(self):
        return self.slug

    def snippet(self):
        return self.content[:100] + " ..."

    def get_meta_keywords(self):
        return [tag.name for tag in self.tags.all()]

    def get_absolute_url(self):
        return urlunquote(
            reverse("blog:single", kwargs={"slug": str(self.slug)}))