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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:37:59+00:00 2026-05-27T10:37:59+00:00

I am currently working on a form that displays information about a specific product

  • 0

I am currently working on a form that displays information about a specific product on my website. Each price is represented by a Price object, and each Item has several Price objects associated with it. I have created a ModelForm to display the data in my Item, which works. However, when I try to display the ManyToMany field in my ModelForm, I get a small box that lists all of my Price objects. I need to display custom HTML for the Price objects so that I can have them interact with some JavaScript I have. Below is the code I have thus far:

class Item(models.Model):
    user        = models.ForeignKey(User)
    name        = models.CharField(max_length=200)
    description = models.CharField(max_length=1000)
    category    = models.ForeignKey(Category)
    prices      = models.ManyToManyField(Price, blank=True)
    images      = models.ManyToManyField(Image)
    runs        = models.ManyToManyField(ActivityRun, blank=True)
    date_added  = models.DateTimeField(auto_now_add=True)

    def __unicode__(self):
        return self.name

class ItemForm(ModelForm):
    class Meta:
        model = Item
    description = forms.CharField(widget=TinyMCE())

@login_required
def edit_item(request, item_id):
    item = get_object_or_404(Item, pk=item_id)
    if request.method == 'POST':
        form = ItemForm(request.POST, request.FILES, instance=item)
        if form.is_valid():
            return HttpResponseRedirect("/items/")
    else:
        form = ItemForm(instance=item)

    return render(request, 'edit_item.html', {'form': form})

And the part of my template I am trying to display:

{% for price in form.prices %}
    <span class="price_box" style="width: 200px;">
        <a href="#" class="remove_price">x</a>{{ price.name }} ${{ price.price }}
    <input type="hidden" name="price_name" value="{{ price.name }}">
    <input type="hidden" name="price_cost" value="{{ price.price }}">
    </span>
{% endfor %}

I am not entirely sure how to go about accomplishing this . . .

More specifically, how do I change the HTML for the manytomany display in my form?

  • 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-27T10:38:00+00:00Added an answer on May 27, 2026 at 10:38 am

    One approach is to use an inline_modelformset to edit your prices. This will probably require you to change your Item model to not have a M2M to Price, but rather have Item as an FK to Price.

    This way, you can use a custom form for Price, and have one or more instances of a PriceForm that will be automatically related to an Item. The formset will have the delete functionality as well, which you could handle via Ajax if you wish. You could also dynamically add/remove forms.

    Hope that helps you out.

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

Sidebar

Related Questions

I am currently working on a website that is an advertisement portal for businesses.
I have been working on a form that presents some specific elements in a
I am currently working on a data input form that will take as in
Currently working with NSURLConnection. Found a great website showing important delegate methods coming with
Am currently working on an application that requires users to submit posts and comments
I am working on a web page that offers a form with a dropdown
I'm having some serious issues with a WinForm application that I'm working on. Currently,
I am currently working on a project which contains a window, that has a
I'm currently working on a Windows Forms GUI and I have a Combo that
I'm currently working on a project that uses django-registration and Django CMS. When display

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.