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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:58:17+00:00 2026-06-09T21:58:17+00:00

currently I’m trying to get multi upload in my admin interface working. I’m using

  • 0

currently I’m trying to get multi upload in my admin interface working.
I’m using the code Luril Garmash provided in his blog:
http://garmoncheg.blogspot.de/2011/07/django-creating-multi-upload-form.html
He’s using the very nice jQuery plugin for multi uploading files from Sebastian Tschan:
http://blueimp.github.com/jQuery-File-Upload/
So do I.

Okay, here’s my structure:

models.py:

class Photoalbum(models.Model):
    event = models.OneToOneField(Event, help_text="Liste der Events ohne Fotoalbum")
    date = models.DateField(auto_now=True)
    facebook = models.BooleanField()

class PhotoalbumImage(models.Model):
    album = models.ForeignKey(Photoalbum, related_name='images', null=True)
    filename = models.CharField(max_length=60, blank=True, null=True, editable=False)
    image = models.FileField(upload_to=storage, editable=False)
    key_data = models.CharField(max_length=90, unique=True, blank=True, null=True, editable=False)
    upload_date = models.DateTimeField(auto_now=True)

I extended the change_form.html template for Photoalbum in order to show the jQuery multi upload form on the add / change site of the Photoalbum model.

Here’s the view logic:

views.py:

    def multiuploader(request):

    #getting file data for farther manipulations
    file = request.FILES[u'files[]']
    wrapped_file = UploadedFile(file)
    filename = wrapped_file.name
    file_size = wrapped_file.file.size
    log.info ('Got file: "%s"' % str(filename))

    #writing file manually into model
    #because we don't need form of any type.
    image = PhotoalbumImage()
    image.filename=str(filename)
    image.image=file
    image.key_data = image.key_generate
    image.save()
    log.info('File saving done')

    #getting thumbnail url using sorl-thumbnail
    im = get_thumbnail(image, "80x80", quality=50)
    thumb_url = im.url

    #settings imports
    try:
        file_delete_url = settings.MULTI_FILE_DELETE_URL+'/'
        file_url = settings.MULTI_IMAGE_URL+'/'+image.key_data+'/'
    except AttributeError:
        file_delete_url = 'multi_delete/'
        file_url = 'multi_image/'+image.key_data+'/'

    #generating json response array
    result = []
    result.append({"id":image.id,
                   "name":filename, 
                   "size":file_size, 
                   "url":file_url, 
                   "thumbnail_url":thumb_url,
                   "delete_url":file_delete_url+str(image.pk)+'/', 
                   "delete_type":"POST",})
    response_data = json.dumps(result)

    #checking for json data type
    #big thanks to Guy Shapiro
    if "application/json" in request.META['HTTP_ACCEPT_ENCODING']:
        mimetype = 'application/json'
    else:
        mimetype = 'text/plain'
    return HttpResponse(response_data, mimetype=mimetype)
else: #GET
    return HttpResponse('Only POST accepted')

this method is called for each file uploaded by the plugin.
note: the file upload saves the files to the filesystem and database seperately from the photoalbum, by clicking on “start upload”.

Note: my photoalbum add / change template shows the multiuploader for my photoalbumimages on the top with “add files” and “start upload” and on the bottom the form fields for the photoalbum on the bottom with the standard django admin save buttons.
sry that i can’t provide a picture because my connection is very, very slow (TOO SLOW) at the place I’m right now.

Thats the point were my problem begins: the files are saved but the photoalbum isn’t. I need a save way to save the correct primary key of the photoalbum into each saved file as foreign key.
My first idea was to handle this problem with the session, save all saved file id’s into a list and within the post_save signal for the photoalbum, get those id’s and save the correct photoalbum id to those files. But I don’t think one should access the session within the model.
My second idea is to create a temp model, e.g. UploadedPhotos, where I store all the file id’s and on post_save signal for the photoalbum, get those id’s.

This just doesn’t feel right.
I think the safest way to accomplish my needs would be to upload the files AFTER the photoalbum has been created (after clicking on Save in the Photoalbum model). Then a primary key for the photoalbum would exist and I could save it to each file.
But I don’t have any idea to get this working.

Big thanks for your help in advance.
Greetings

  • 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-06-09T21:58:19+00:00Added an answer on June 9, 2026 at 9:58 pm

    okay i achieved my requirements trough populating a hidden form field with the uploaded and saved id’s of the photos in the photoalbum model. this field is a charfield and i put all the id’s in it and seperate them with “//” and parse it on the post_save signal of the photoalbum.

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

Sidebar

Related Questions

Currently I am using HTML files for parts of my user interface. I display
Currently I’m trying to get the hang of a block copy with my current
currently, I`m implementing a map App with Mono4Droid and there I`m using a WebView
Currently, I'm working on a project where I have a server - client relationship
Currently working with converting SQLException error messages into messages that are more useful for
Currently I have this code: <?php echo '<meta name=robots content=noindex>'; $arr = json_decode(file_get_contents(http://media1.clubpenguin.com/play/en/web_service/game_configs/ paper_items.json),true);
Currently I am trying to use a bunch of custom perl modules, test.pm as
Currently i'm having trouble using two functions in my -(void)viewDidLoad , both of these
Currently I am using Amazon Cloudfront to service static objects on my ASP.Net MVC3
Currently I have in my code tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(addCompoundToLabel:)]; My code

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.