Django 4 - depending on choices , how show different fields using admin

Viewed 30

Anyone please tell me depending on choices , show to fields using admin

=== Models.py

from django.db import models

class Project(models.Model):
     A = 'A'
     B = 'B'
     PROJECT_TYPE_CHOICES = (
         (A, 'Plan Type A'),
         (B, 'Plan Type B'),
     )
     project_type = models.CharField(max_length=100, 
     choices=PROJECT_TYPE_CHOICES)
     name = models.CharField(max_length=500)
     business = models.CharField(max_length=500)

=== admin.py

from django.contrib import admin
from .models import Project

admin.site.register(Project, ProjectAdmin)

i want if i choices A show fields name

if i choices B show fields business

Thanks

1 Answers

I am not sure but i hope it will work.

> class Project(models.Model):
>     def fields(self, request):
>         if obj is A:
>             return ('name')
>         return ('name')
Related