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

  • Home
  • SEARCH
  • 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 8091383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:03:04+00:00 2026-06-05T20:03:04+00:00

All my object newmedia are saving with the same name. how can I fix

  • 0

All my object newmedia are saving with the same name.
how can I fix this?

#view.py
if request.method == 'POST':
    formset = MediaFormSet(request.POST, request.FILES)
    if formset.is_valid():
        Page_key = Page.objects.get(pk=1)
        slide = SlideshowComponent(page=Page_key, order=0, label="slideshow", x=0, y=0, width=0, height=0, viewport_type="simle_page", keywords="slideshow")
        slide.save()      
        for filename, file in request.FILES.iteritems():
            name = request.FILES[filename].name               
        for form in formset.forms:        
            file_type = file.content_type
            if file_type == "image/png" or file_type == "image/jpeg" or file_type == "image/gif":
                newmedia = formset.save(commit=False)
                newmedia.filename = name
                newmedia.content_type = "photos"
                newmedia.save()
  • 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-05T20:03:05+00:00Added an answer on June 5, 2026 at 8:03 pm

    Instead i have 2 for, i do everything in only one for.

    for file in request.FILES.getlist('form-0-source'):
        file_type = file.content_type
        if file_type == "image/png" or file_type == "image/jpeg" or file_type == "image/gif":
            name= file.name.split('.')[0]
            newmedia = Media(source=file, filename=name, content_type = "photos", created='03/25/12')
            newmedia.save()                  
            image2 = ImageComponent(page=Page_key, order=0, label="imagem", x=0, y=0, width=0, height=0, viewport_type="simle_page", keywords="imagem", media=newmedia, is_slideshow='true')
            image2.save()
            slide.image.add(image2)                 
        else:
            return render_to_response('revista_digital/error.html', context_instance=RequestContext(request))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I list all Object Properties associated to a instance in Jena? For
In my code this.options returns object with .all object nested. Yet when I try
In PHP, all object-variables are actually pointers to objects (no?), the language handles this
The problem is that all Object attributes apart from 'name' call the error 'id/url/whatever
iam trying to get all object's xpath's from loaded page via selenium something similar
I want to have one directory for all object files and create Common.pri file
I need to write a query that returns all object less that or equal
I retrieve a list of ObjectId and I want to retrieve all object in
Possible Duplicate: Is there a simple way of obtaining all object instances of a
I come from the Java world, so to me it's all object.foo() , but

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.