Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1102095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:07:57+00:00 2026-05-17T01:07:57+00:00

I’d like to implement a functionality in an app of mine, but I don’t

  • 0

I’d like to implement a functionality in an app of mine, but I don’t know how to go about it. What I want is this: I have a model class that uses imagekit to save its images, and I’d like to have the users being able to update the images easily for the vehicles without having to edit each respective vehicle record.

How they’ll do this is that there will be a folder named originals and it’ll contain folders for each vehicle in the format <stock_number>/PUBLIC If a user moves images into the PUBLIC folder for a vehicle, when the script is executed, it’ll compare those images with the current ones and update them if those in the PUBLIC folder are newer. If the record has no images, then they will be added. Also, if the images have been deleted from the site_media directory, then their links should be deleted from the database.

How can I go about this in an efficient way? My models are as below:

class Photo(ImageModel):
   name = models.CharField(max_length = 100)
   original_image = models.ImageField(upload_to = 'photos')
   num_views = models.PositiveIntegerField(editable = False, default=0)
   position = models.ForeignKey(PhotoPosition)
   content_type = models.ForeignKey(ContentType)
   object_id = models.PositiveIntegerField()
   content_object = generic.GenericForeignKey('content_type', 'object_id')

   class IKOptions:
      spec_module = 'vehicles.specs'
      cache_dir = 'photos'
      image_field = 'original_image'
      save_count_as = 'num_views'


class Vehicle(models.Model):
   objects = VehicleManager()
   stock_number = models.CharField(max_length=6, blank=False, unique=True)
   vin = models.CharField(max_length=17, blank=False)
   ....
   images = generic.GenericRelation('Photo', blank=True, null=True)

Progress Update
I’ve tried out the code, and while it works, I’m missing something as I can get the image, but after that, they aren’t transferred into the site_media/photos directory…am I suppossed to do this or imagekit will do this automatically? I’m a bit confused.

I’m saving the photos like so:

Photo.objects.create(content_object = vehicle, object_id = vehicle.id, 
                     original_image = file)
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T01:07:57+00:00Added an answer on May 17, 2026 at 1:07 am

    My advice is running django script in a crontab job, lets say, 5 in 5 minutes.

    The script would dive into the image folders and compare the images with the records.

    A simplified example:

    # Set up the Django Enviroment
    from django.core.management import setup_environ 
    import settings 
    setup_environ(settings)
    import os
    from your_project.your_app.models import *
    from datetime import datetime
    
    vehicles_root = '/home/vehicles'
    for stock_number in os.listdir(vehicles_root):
        cur_path = vehicles_root+'/'+stock_number
        if not os.path.isdir(cur_path):
            continue # skip non dirs
        for file in os.listdir(cur_path):
            if not isfile(cur_path+'/'+file):
                continue # skip non file
            ext = file.split('.')[-1]
            if ext.lower() not in ('png','gif','jpg',):
                continue # skip non image
            last_mod = os.stat(cur_path+'/'+file).st_mtime
            v = Vehicle.objects.get(stock_number=stock_number)
            if v.last_upd < datetime.fromtimestamp(last_mod):
                # do your magic here, move image, etc.
                v.last_upd = datetime.now()
                v.save()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I don't have much knowledge about the IPv6 protocol, so sorry if the question
For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.