Hello Comunity. I am new in the Django Forum and this is my first question, but I have a year following this site.
This is my problem.
In the default Django Admin Site, if a model is registered with ForegingKey fields and those are included in readonly_fields (using the model property or the get_readonly_fields method) the value of the field is rendered with a link to the Change View, but this Doesn’t work on a custom Django Admin Site . E.g.: I have this two models:
class ModelA(models.Model): field_a = models.CharField(max_length=50) class ModelB(models.Model): model_a = models.ForeignKey(ModelA, on_delete=models.PROTECT)
I registered in the default Django Admin Site:
admin.register(ModelA) @register(ModelB) class ModelBAdmin(admin.ModelAdmin): model = ModelB readonly_fields = ["model_a"]
So I get in the Change View of ModelB in the Admin the value of the field ( str of the model) with a link to the Change View of the related model:
But if I register the models in a Custom Admin Site, the link is not generated.
How can I extends my Custom Admin Site in order to generate those links?
PD1: I know I can code custom methods to build the links, but this is not a DRY way of do it and doesn’t work well with get_readonly_fields method
PD2: If I register the related model (ModelA in the example) in the default Admin Site the link is generated, but point to the default Admin Site, brokening the purpose of the Custom Admin Site.
PD3: Question posted in StackOverflow: python - Custom Django Adminsite Doesn't show link to read_only ForeignKey field - Stack Overflow