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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:26:00+00:00 2026-05-22T12:26:00+00:00

I’m trying to figure out how to upload an image and get user input

  • 0

I’m trying to figure out how to upload an image and get user input on a single form.
My models:

class Image(models.Model):
    artist = models.ForeignKey('Artist')
    image = models.ImageField(upload_to="assets/images")

class Album(models.Model):
    artist = models.ForeignKey(Artist,null=True)
    notes = models.CharField(max_length = 50)
    display = models.BooleanField()
    date_created = models.DateTimeField(auto_now_add=True)

My forms

class AlbumForm(forms.ModelForm):
    class Meta:
        model = Album
        fields = ('notes',)

class ImageForm(forms.ModelForm):
    class Meta:
        model = Image
    exclude = ('artist')`

I think my view is wrong and how would I pass the two forms to the template? What would the template look like to render the two forms? I want to use a single submit button.

def create(request):
    form1 = ImageForm(request.POST, request.FILES or None)
    form2= AlbumForm(request.POST or None)
    if form2.is_valid() and form1.is_valid():
        image = form1.save(commit=False)
        image.artist = Artist.objects.get(pk=3)
        image.save()
        album = form2.save(commit=False)

        album.save()
        if 'next' in request.POST:
            next = request.POST['next']
        else:
            next = reverse('art_show')
        return HttpResponseRedirect(next)
    return render_to_response(
        'art/create.html',
        {'ImageForm':form1},
        { 'AlbumForm': form2},
        context_instance = RequestContext(request)
)
  • 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-22T12:26:00+00:00Added an answer on May 22, 2026 at 12:26 pm

    You could probably do something like this:

    <form action="." method="post" enctype="multipart/form-data">
        {{ImageForm.image}} <br />
        {{AlbumForm.notes}} <br />
        {{AlbumForm.display}} <br />
        ...
        <input type="submit" value="Save" />
    </form>
    

    This will return both form1 and form2 objects in your request.POST object.

    views.py:

    ...
    return render_to_response('art/create.html', 
        {'ImageForm': form1, 'AlbumForm': form2}, 
        context_instance = RequestContext(request)
    )
    

    Or you could do this:

    ...
    return render_to_response('art/create.html',
        locals(), 
        context_instance = RequestContext(request)
    )
    

    Although, the second one will add all variables your function uses so you should make sure that if you use it that your function won’t be using any builtin names. Usually uncommon, but you should just make sure.

    EDIT: Added a submit button to make it clear you only need one. Also added the view’s response.

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

Sidebar

Related Questions

No related questions found

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.