sách gpt4 ai đã đi

django - 集成 Photologue

In lại 作者:行者123 更新时间:2023-12-04 22:17:14 26 4
mua khóa gpt4 Nike

我想将 photologue 与我的 Django 应用程序集成,并使用它在车辆库存中显示照片......有点像 Boost Motor Group Inc. 提供的内容。我已经集成了该应用程序,所以下一步我正在尝试弄清楚如何将其连接到我的车辆模型以及如何显示照片。我的车辆模型看起来像这样 BTW

class Vehicle(models.Model):
stock_number = models.CharField(max_length=6, blank=False)
vin = models.CharField(max_length=17, blank=False)
common_vehicle = models.ForeignKey(CommonVehicle)
exterior_colour = models.ForeignKey(ExteriorColour)
interior_colour = models.ForeignKey(InteriorColour)
interior_type = models.ForeignKey(InteriorType)
odometer_unit = models.ForeignKey(OdometerUnit)
status = models.ForeignKey(Status)
odometer_reading = models.PositiveIntegerField()
selling_price = models.PositiveIntegerField()
purchase_date = models.DateField()
sales_description = models.CharField(max_length=60, blank=False)
feature_sets = models.ManyToManyField(FeatureSet, blank=True)
features = models.ManyToManyField(Feature, blank=True)

def __unicode__(self):
return self.stock_number

1 Câu trả lời

我使用 ImageKit(太棒了!)

模型.py

from imagekit.models import ImageModel
class Photo(ImageModel):
name = models.CharField(max_length=100)
original_image = models.ImageField(upload_to='photos')
num_views = models.PositiveIntegerField(editable=False, default=0)
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type', 'object_id')

class IKOptions:
# This inner class is where we define the ImageKit options for the model
spec_module = 'cms.specs'
cache_dir = 'photos'
image_field = 'original_image'
save_count_as = 'num_views'

class Vehicle(models.Model):
images = generic.GenericRelation('Photo', blank = True, null = True)

规范文件
from imagekit.specs import ImageSpec 
from imagekit import processors
from imagekit.lib import *

# first we define our thumbnail resize processor
class ResizeThumb(processors.Resize):
width = 100
height = 75
crop = True

# now lets create an adjustment processor to enhance the image at small sizes
class EnchanceThumb(processors.Adjustment):
contrast = 1.2
sharpness = 1.1

# now we can define our thumbnail spec
class Thumbnail(ImageSpec):
processors = [ResizeThumb, EnchanceThumb]

在您的模板中,您将像这样访问此缩略图:
{% for p in vehicle.images.all %}
{{ p.get_thumbnail.url }}
{% endfor %}

admin.py 可能如下所示:
class ImagesInline(generic.GenericTabularInline):
model = Photo
max_num =4

class VehicleAdmin(admin.ModelAdmin):
inlines = [ImagesInline]

Về ImageKit

将文件 specs.py 添加到您的应用程序并像这样告诉 ImageKit
  class IKOptions:
# This inner class is where we define the ImageKit options for the model
spec_module = 'cms.specs # ur_app.specs

向您的照片模型添加一个字段以保存它显示的 View /内容类型。即选择字段

在 View /模板中,您可以对其进行过滤

关于django - 集成 Photologue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1556279/

26 4 0
Bài viết được đề xuất: scala - Scala 中的条件循环转换
Bài viết được đề xuất: wpf静态绑定(bind)问题
Bài viết được đề xuất: regex - 除了空格用双引号引起来之外,Perl如何在空格上分割行?
Bài viết được đề xuất: vim:删除显示行而不是物理行
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com