整合Photologue

时间:2009-10-12 18:53:55

标签: django imagekit django-imagekit photologue

我希望将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

2 个答案:

答案 0 :(得分:8)

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

答案 1 :(得分:5)

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

在Photo-Model中添加一个字段,以保存它显示的视图/内容。即ChoiceField

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