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 6249469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:14:39+00:00 2026-05-24T13:14:39+00:00

Please forgive my naiveté with Django. I want to create my own method which

  • 0

Please forgive my naiveté with Django.

I want to create my own method which works much like prepopulated_fields for my custom admin page. Basically, when you put the url of an image in one field, I’d like to populate another field with the name of the image, height and width via javascript.

What would be the best approach? Just override the change_form.html and include my own JS lib? Write a custom widget?

  • 1 1 Answer
  • 0 Views
  • 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-24T13:14:39+00:00Added an answer on May 24, 2026 at 1:14 pm

    Using Javascript would be a probable move, if for some reason you want to show the attributes of the image.

    See Javascript – Get Image height for an example of doing this.

    If there’s no need to show it at the form level but to simply populate the usually prefer to do this at the model level, such as

    from PIL import Image
    import StringIO
    import urllib2
    
    class MyModel(models.Model):
        # ... fields 1,2,3 etc, and assuming the url field is called image_url
    
        def pre_save():
            # obtain attributes of image from url field
            # save it to various fields
            img = urllib2.urlopen(self.image_url).read()
            im = Image.open(StringIO.StringIO(img))
            self.image_width, self.image_height = im.size
    
        def save(self, *args, **kwargs):
            self.pre_save()
            super(MyModel, self).save(*args, **kwargs)
    

    Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

please forgive my windows ignorance, Is there an application which can show me which
I am new to Django and Python, please forgive me if this is a
I am new to django so please forgive me if this turns out to
Please forgive my long question. I have an idea for a design that I
Please forgive me if this is an obvious one. I have an unknown amount
Please forgive the verbosity of the following code example. Using Delphi 2009, I created
Please forgive my programming knowledge. I know this is a simple thing, but I
Please forgive the simplicity of this question. The answer will be obvious to many
Please forgive me if this is answered on SO somewhere already. I've searched, and
Please forgive my ignorance, but I wasn't able to find an answer elsewhere. I

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.