I am using Django 1.9.
I have some models:
class MyOtherModel:
my_other_prop = models.IntergerField()
class MyModel:
some_prop = models.IntegerField()
my_other_model = models.ForeignKey(MyOtherModel)
And my admin model is:
class MyModelAdmin(ModelAdmin):
model = MyModel
fields = ['some_prop', 'my_other_model']
Now this by default will give me the ability to set my_other_model
, create my_other_model
and update my_other_model
on the form. What I want to do is disable editing(updating) my_other_model
. I still want to be able to set it and still want to be able to create one from MyModelAdmin
. Since MyOtherModel
is not exposed via admin any other place the idea is that from the admin section point of view the model is immutable.
I've dug around the Django docs and have Googled quite a bit but am not finding a way to accomplish this. I don't want the field to be read-only because I want to be able to create them. I don't think I want to override get_readonly_fields()
to return false if the object exists in this case because I would still want to be able to change which MyOtherModel
MyModel
has.. just not edit MyOtherModel
itself.
Could anyone point me in the right direction here? Should I be using a different approach? Any advice would be appreciated, thanks much!