4

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
Mariusz Jamro
  • 30,615
  • 24
  • 120
  • 162
  • Where do the photos belong? On the `Vehicle` model? Do you want one photo or many? Can one photo belong to many vehicles? IMO it's not possible to answer your question with any degree of accuracy until we know a bit more about what you're trying to accomplish. – Dominic Rodger Oct 12 '09 at 19:57
  • The photos belong on the Vehicle model and will be many...on the inventory list, I want to have four thumbnails for each vehicle then on the vehicle details page I have all the other photos. Also, the vehicles can't share photos –  Oct 13 '09 at 05:05

2 Answers2

9

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.

Justin Driscoll
  • 654
  • 4
  • 10
5

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

Zoe
  • 27,060
  • 21
  • 118
  • 148
vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
  • 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 –  Oct 16 '09 at 16:36
  • this is a task for ur templates – vikingosegundo Oct 16 '09 at 17:03
  • I've tried out this and all I get is Error was: Unable to load imagekit config module: cms.specs... –  Oct 16 '09 at 17:08
  • 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 Oct 16 '09 at 17:10
  • OneToOneField: http://docs.djangoproject.com/en/dev/topics/db/models/#one-to-one-relationships – vikingosegundo Oct 16 '09 at 17:14
  • this doesn't help...plus I'll have 30+ images so adding them independently isn't feasible. how about photologue...? –  Oct 16 '09 at 17:15
  • ImageKit has the same ideas as photolouge. – vikingosegundo Oct 16 '09 at 17:32
  • let me try and set up photologue...I want to compare the two of them and see for my self. thanks for the help. –  Oct 16 '09 at 17:44
  • 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. –  Oct 23 '09 at 18:40
  • 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 Oct 23 '09 at 20:06