0

It seems that Django happens to just use a <p> Tag for read-only text fields inside forms (at least tabular inlines in admin forms).

What I want is, to display an URL inside a tabular inline (just using one line if possible). Unfortunately that URL tends to be rather long. So the best would be, when the URL would be inside some text field, where I can scroll or just select the whole content with CNTRL-A to get the link.

But the field should be read-only. When I do that in the admin, it changes the whole output to <p> and thus the URL will be displayed in full length and taking over the whole width of the screen -- and compressing other fields -- what is rather ugly.

Any solution?

Juergen
  • 12,378
  • 7
  • 39
  • 55
  • is the url in a model of your's ? And are you trying to view it from the admin panel? Would you consider adding a screenshot? – because_im_batman Jun 29 '21 at 19:16
  • It is a foreign URL and it is not about the URL. It is just some URL, what needs to be present, to be copied. That is it. It also could be any long text string. The problem is, that the `

    ` tag happens to take over the whole horizontal space. It would be OK, when the string is cut at some point (like it happens inside some `` field. But I can't cut the content itself, since it should be copy-able in full.

    – Juergen Jun 29 '21 at 19:17
  • 1
    If its in the admin panel, you should be able to write a custom admin which overrides the default behaviour of that field to show whatever you want instead of the

    tag. This link contains some examples: https://stackoverflow.com/questions/910169/resize-fields-in-django-admin

    – because_im_batman Jun 29 '21 at 19:25
  • 1
    Thanks for this, but I am not sure, if this will work for a read-only field. I guess that either read-only will overwrite the widget or the widget will overwrite read-only. – Juergen Jun 29 '21 at 19:33
  • Now I tested it. Like I expected, with read-only set for the field, the widget is totally ignored by Django. When read-only is not set, the widget is used, but the field will be editable -- which I do not want. – Juergen Jun 29 '21 at 20:07

0 Answers0