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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:09:38+00:00 2026-05-16T14:09:38+00:00

I am not sure this is even possible without modifying the Admin interface. I

  • 0

I am not sure this is even possible without modifying the Admin interface.

I have a model called “Quote” that can contain multiple “Product” models. I connect the two using an intermediate model “QuoteIncludes”. Here are the three models as they currently stand:

class Product(models.Model):
    name = models.CharField(max_length=100)
    short_desc = models.CharField(max_length=200)
    default_cost = models.DecimalField(max_digits=15, decimal_places=2)
    default_price = models.DecimalField(max_digits=15, decimal_places=2)
    shipping_per_unit = models.DecimalField(max_digits=9, decimal_places=2)
    weight_in_lbs = models.DecimalField(max_digits=5, decimal_places=2)

    def __unicode__(self):
        return self.name

class Quote(models.Model):

    ## Human name for easy reference
    name = models.CharField(max_length=100)
    items = models.ManyToManyField(Product, through='QuoteIncludes')

    def __unicode__(self):
        return self.name

class QuoteIncludes(models.Model):

    ## Attach foreign keys between a Quote and Product
    product = models.ForeignKey(Product)
    quote = models.ForeignKey(Quote)

    ## Additional fields when adding product to a Quote
    quantity = models.PositiveIntegerField()
    per_unit_cost = models.DecimalField(max_digits=15, decimal_places=2)
    per_unit_price = models.DecimalField(max_digits=15, decimal_places=2)

    def _get_extended_price(self):
        """Gets extended price by multiplying quantity and unit price."""
        if self.quantity and self.per_unit_price:
            return self.quantity * self.per_unit_price
        else:
            return 0.00

    extended_price = _get_extended_price

What I would like to be able to do is create a Quote in the Admin interface such that when I’ve filled in both the quantity and the per_unit_price of a line item, it fills in the “extended_price” as a product of the two when I tab over. I think it requires adding some AJAX in there.

Annotated picture describing what I would like

  • 1 1 Answer
  • 1 View
  • 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-16T14:09:38+00:00Added an answer on May 16, 2026 at 2:09 pm

    Info on how to include js in your model admin:
    http://docs.djangoproject.com/en/dev/ref/contrib/admin/#modeladmin-media-definitions

    For example:

    class Media:
        js = (
            'http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js',
            '/media/js/calculate.js',
        )
    

    And your script could look something like this:

    function currencyFormat(nStr) {
        nStr += '';
        x = nStr.split('.');
        x1 = x[0];
        x2 = x.length > 1 ? '.' + x[1] : '';
        var rgx = /(\d+)(\d{3})/;
        while (rgx.test(x1)) {
            x1 = x1.replace(rgx, '$1' + '.' + '$2');
        }
        return x1 + x2;
    }
    
    jQuery(document).ready(function($){
        $('input[id$=quantity], input[id$=per_unit_cost]').live('keyup', function() {
            var $tr = $(this).parents('tr');
            var quantity = parseInt($tr.find('input[id$=quantity]').val());
            var count = parseInt($tr.find('input[id$=per_unit_cost]').val());
    
            if(quantity && count) {
                $tr.find('input[id$=per_unit_price]').html(currencyFormat(quantity * count));
            }
        });
    });
    

    Something like that.

    Just added the currency format function in case you wanted to use it.

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

Sidebar

Related Questions

I am not completely sure that this is possible from within PHP or even
I'm not sure this is even possible but I know if it is, the
First of all I'm not sure this is even possible, however I need to
I'm not sure if this is even possible, but is there a way to
Ok, not sure if this is even possible, but I want to change the
Hello! I'm not even sure if this is possible, but hopefully it is in
I'm not even sure what this principle is called or how to search for
I'm not even sure what this is called? But I'm trying to learn what
Not sure if this is even possible, but I think it's worth asking. What
I'm not even sure if this is possible, but I need to send POST

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.