django - How can I dynamically change list of fields displayed in admin interface depending on the choice in the first field? -
i want admin interface show disctrict field if choose 'b' category. if choose 'w' want fields of offer model displayed. possible show selected (filtered) fields in admin page depending on choice in other field in same model? in advance help.
my models:
class category(models.model): name_choices = ( ('b', 'black'), ('w', 'white'), ) name = models.charfield(max_length=200, choices=name_choices) class meta: verbose_name_plural = 'categories' def __unicode__(self): return self.get_name_display() class offer(models.model): category = models.foreignkey(category, verbose_name='kategoria') city = models.charfield(max_length=128, verbose_name='miasto') province = models.charfield(max_length=3) district = models.charfield(max_length=128, verbose_name='dzielnica') def __unicode__(self): return "offer number %s" % (self.id)
first of must tell, django works in sync way. if want choose input use, must send request , wait feedback. in opinion there're no straight way task correctly.
and see few solutions:
1) can use jquery that. main problem django has own admin system built-in widgets. can try customize in 2 ways:
- take app option (for example, django-admin-tools) , create custom behavior on form;
manage.py collectstatic, after going admin folder , create custom jquery script.
2) build custom admin form model modelchoicefield. don't quit sure field behavior you, can investigate that.
if need task, choose first way admin static , custom jquery.
Comments
Post a Comment