1

Hello smart people of SO. I am trying to make a dependent Django admin form. Where if a user selects Channel as a sku type, then he just has to add service category and product category and remaining fields become inactive for him and it has null values stored in them. If a user select direct then all fields become active and he can add data into all fields. In a nutshell, I am looking for column activity based on the values in the sku type field. Not sure if we can do it in Django at this point or not. I am using Django 1.10.

I have a model of my app as following

from django.db import models
from decimal import Decimal

    class Sku(models.Model):
        sku_type = (
            ('Channel', 'Channel'),
            ('Direct', 'Direct'),
            ('Warranty', 'Warranty'),
            ('abc', 'abc'),
        )
        sku_type = models.CharField("SKU Type", choices=sku_type, default='Channel', max_length=20)
        sku = models.CharField("SKU", primary_key=True, max_length=20)
        date_added = models.DateTimeField("Date when Added", auto_now=False, auto_now_add=True)
        date_updated = models.DateTimeField("Last Updated Date", auto_now=True, auto_now_add=False)
        service_category = models.CharField(max_length=200, blank=True, null=True)
        product_category = models.CharField(max_length=200, blank=True, null=True)
        product_description = models.TextField(blank=True, null=True)
        sap_description = models.TextField(blank=True, null=True)

        def __str__(self):
            return self.sku
nomad
  • 973
  • 2
  • 9
  • 22
  • Because what you're asking has to be done in the frontend, you must do it via JS or jQuery. Django Admin already provides you (out of the box) jQuery. – nik_m Mar 25 '17 at 06:38
  • I am talking about Django-Admin. Is there a built-in functionality which does that? – nomad Mar 27 '17 at 13:40
  • No there is not a built-in functionality. This is front-end things and solved by jQuery where Django Admin already provides it to you. So, create a `js` file, at the top write this `const $ = django.jQuery;` (now you have `jQuery` available, write some `jQuery` and then [include it](http://stackoverflow.com/questions/16014719/adding-a-jquery-script-to-the-django-admin-interface) to your `ModelAdmin` class. – nik_m Mar 27 '17 at 17:42

0 Answers0