views:

607

answers:

2

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
+3  A: 

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.

jdriscoll
+1 as a rather pathetic way of saying thanks for Photologue - currently powering aarongriffin.co.uk very nicely.
Dominic Rodger
+2  A: 

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

edit

add the file specs.py to ur 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

edit 2

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

vikingosegundo
will this enable me to specify which photos will be displayed at which position...e.g at the listings page I want to display four photos (front view, side view, interior and dashboard)? I like the enitr imagekit idea though...let me try it out
this is a task for ur templates
vikingosegundo
I've tried out this and all I get is Error was: Unable to load imagekit config module: cms.specs...
if u allways got an identical set of photos, u might want to add every of it independently to ur model front_image = models.OneToeOneField(Photo)
vikingosegundo
see my edit for ur error
vikingosegundo
and dont hesitate to vote up :D
vikingosegundo
OneToOneField: http://docs.djangoproject.com/en/dev/topics/db/models/#one-to-one-relationships
vikingosegundo
this doesn't help...plus I'll have 30+ images so adding them independently isn't feasible. how about photologue...?
ImageKit has the same ideas as photolouge.
vikingosegundo
see my second edit for an idea
vikingosegundo
let me try and set up photologue...I want to compare the two of them and see for my self. thanks for the help.
my final idea should work with photolouge too
vikingosegundo
BTW vehicle.images.all() gives me this error: Could not parse the remainder: '()' from 'vehicle.images.all()' I didn't need to use this part of your answer till now but now that I do it doesn't work for me.
oh, yes: In templates you will only be able to call functions without sending parameters, and you dont use () in that case. just use vehicle.images.all
vikingosegundo