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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:22:56+00:00 2026-06-09T09:22:56+00:00

Consider these pseudo models: class Category(models.Model): name = models.CharField() class Product(models.Model): name = models.CharField()

  • 0

Consider these pseudo models:

class Category(models.Model):
    name = models.CharField()

class Product(models.Model):
    name = models.CharField()
    code = models.CharField()
    category = models.ForeignKey(Category)
    price = models.DecimalField()
    stock = models.IntegerField()

class AlternativeProduct(Product):
    original_product = models.ForeignKey(Product, related_name="alternative", editable=False)

I want to use inlines to be able to quickly add a product and its alternative option without typing duplicate data (ONLY code, stock and price differentiate).

admin.py

class AlternativeProductInline(admin.TabularInline):
    model = AlternativeProduct
    formset = AlternativeProductInlineFormset
    fk_name = "original_product"
    fields = ["code", "price", "in_stock"]
    max_num = 1
    extra = 0


class ProductAdmin(admin.ModelAdmin):
    form = ProductAdminForm
    inlines = [AlternativeProductInline]

Ofcourse this will raise ValidationError, because AlternativeProduct is missing a category.

Now I could setup a default value to fix that:

class Product(models.Model):
    name = models.CharField()
    code = models.CharField()
    category = models.ForeignKey(Category, default=1)
    price = models.DecimalField()
    stock = models.IntegerField()

But besides the fact this id might not exist it still needs to be corrected. Is there any other way (besides Javascript) to copy the category value of the genuine product to the alternative inline product ‘under the hood‘

I have tried to change the admin_view, but it gets hackish, perhaps a custom view would be a nice solution although javascript is a less time consuming approach.

  • 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-09T09:22:57+00:00Added an answer on June 9, 2026 at 9:22 am

    Javascript does seem to be the easy approach to achieve this.

    $(document).ready(function(){
        $('#alternative-group thead th:nth-child(2)').hide();
        $('#alternative-group tbody td:nth-child(1) p').hide();
        $('#alternative-group tbody td:nth-child(3)').hide();
        $('#id_alternative-0-category').hide();
    
        var product_category = $('#id_category option:selected').val();
        $('#id_alternative-0-category').val(product_category);
    
        $("#id_category").change(function() {
            product_category = $('#id_category option:selected').val();
            $('#id_alternative-0-category').val(product_category);
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider these pseudo models: class City(models.Model): name = models.CharField() region = models.ForeignKey(Region) class Region(models.Model):
Consider these pseudo classes: class Foo(models.Model): pass class Bar(models.Model): foo = models.ForeignKey(Foo) I would
Consider these pseudo models: class BaseProduct: quantity_available = Integer class Box(BaseProduct): items_in_box = Integer
consider these POCOs: class Foo { int Id {get;set;} string Name {get;set;} } class
Consider these 2 pieces of code (you can assume execeptionObj is of type Object
To give an idea of my requirement, consider these classes - class A {
Consider these two structures: struct Task { public Int32 Id; public String Name; public
Consider the following two methods, written in pseudo code, that fetches a complex data
Consider these classes: #include <iostream> #include <string> class A { std::string test; public: A
consider these tables: leagues [ id,name ] teams [ id,name,leaguesid] FK: (leaguesid) -> (leagues.id)

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.