我想photologue与我的Django应用程序集成,并用它在车辆显示的库存照片......有点像什么是加速汽车集团公司提供我已经集成了应用程序,所以下一步我”米试图找出是如何把它挂在我的汽车模型,以及如何显示照片。我的车辆模型看起来像这样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
有帮助吗?

解决方案

我用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

在视图/模板可以筛选为它

其他提示

有关你的目的,我建议你看看 Django的imagekit (我写了两imagekit和photologue)。它被设计集成到其他应用程序而不是作为一个独立的应用程序本身。在此之后,作为多米尼克说,我们需要更多地了解您的要求。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top