整合照片记录

发布于 2024-08-07 10:22:37 字数 1032 浏览 5 评论 0原文

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

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

I want to integrate photologue with my Django app and use it to display photos in a vehicle inventory...kinda like what is offered by Boost Motor Group Inc. I've already integrated the app so the next step which I'm trying to figure out is how to hook it up into my vehicle model and also how to display the photos. My vehicle model looks like this 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

荒岛晴空 2024-08-14 10:22:37

出于您的目的,我建议您查看 django-imagekit (我写了 imagekit 和 photologue) 。它被设计为集成到其他应用程序中,而不是作为一个独立的应用程序本身。之后,正如多米尼克所说,我们需要更多地了解您的要求。

For your purposes I would recommend you check out django-imagekit (I wrote both imagekit and photologue). It was designed to be integrated into other applications as opposed to being a stand-alone application itself. After that, as Dominic said, we'll need to know more about your requirements.

謌踐踏愛綪 2024-08-14 10:22:37

使用 ImageKit(太棒了!)

model.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)  

specs.py

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]

关于 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

向您的照片模型添加一个字段以保存哪种视图/它显示的内容。即 ChoiceField

在视图/模板中您可以对其进行过滤

I use ImageKit (great!)

model.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)  

specs.py

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] 

in your template you will access this thumbnails like this:

{% for p in vehicle.images.all %}
   {{ p.get_thumbnail.url }}
{% endfor %}

admin.py could look like this:

class ImagesInline(generic.GenericTabularInline):
    model = Photo
    max_num =4

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

All about ImageKit

add the file specs.py to your app and tell ImageKit of it like this

  class IKOptions:
        # This inner class is where we define the ImageKit options for the model
        spec_module = 'cms.specs # ur_app.specs

add a field to your Photo-Model to save what kind of view/ content it shows. i.e. ChoiceField

In view/template you can filter for it

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文