Django admin - remove field if editing an object
Posted
by John McCollum
on Stack Overflow
See other posts from Stack Overflow
or by John McCollum
Published on 2010-05-19T15:23:08Z
Indexed on
2010/05/19
16:20 UTC
Read the original article
Hit count: 189
django
|django-admin
I have a model which is accessible through the Django admin area, something like the following:
# model
class Foo(models.Model):
field_a = models.CharField(max_length=100)
field_b = models.CharField(max_length=100)
# admin.py
class FooAdmin(admin.ModelAdmin):
pass
Let's say that I want to show field_a and field_b if the user is adding an object, but only field_a if the user is editing an object. Is there a simple way to do this, perhaps using the fields attribute?
If if comes to it, I could hack a JavaScript solution, but it doesn't feel right to do that at all!
© Stack Overflow or respective owner