2
class BannerAddPage(models.Model):
    BOOL_CHOICES = ((True, 'Live'), (False, 'Pause'))
    TYPE_CHOICES = (('text', 'text'), ('image', 'image'))
    category=models.ForeignKey(Category,blank=True)
    client=models.ForeignKey(Client)
    ad_type=models.CharField(choices=TYPE_CHOICES,default=True)
    ad_name=models.CharField(max_length=800,null=True,blank=True)
    ad_title=models.CharField(max_length=800,null=True,blank=True)
    ad_url1=models.URLField(max_length=800,blank=True,null=True)
    ad_banner2=models.ImageField(upload_to=upload_to1,blank=True,null=True)

See the image here

I want to hide some fields after click on ad_type(choice) field.

doru
  • 9,022
  • 2
  • 33
  • 43
GauravInno
  • 317
  • 1
  • 2
  • 14

1 Answers1

1

Best way is to use form media to add an external javascript file that will listen to the change event of the field ad_type and perform the action you need.

In this case you will need little python and lot more of js, but I think is the clean way.

To add the external js file use the class Media, this answer to another question shows a practical example.

Than you just have to have fun with writing js code, you can use the jQuery already included in django admin.

Hope this helps

Community
  • 1
  • 1
Mauro Rocco
  • 4,980
  • 1
  • 26
  • 40