How can I configure the wrapping of a large long line of text in a form Django?
I have a form with OneToOneField where data is loaded from another table model. But I often have large data sizes there and the displayed text does not fit into the window size. Is it possible to somehow configure the text wrapping to 2-3 lines?
How can I configure the wrapping of a large long line of text in a form?
from django.db import models
# Create your models here.
class ArkiObject (models.Model):
nameobject = models.TextField(verbose_name="Наименование объекта")
def __str__(self):
return self.nameobject
TYPE_OBJECT = [
("1", "Котельная"),
("2", "Сети"),
("3", "БМК"),
("4", "ЦТП"),
("5", "ТГУ"),
]
TYPE_WORK = [
("1", "Реконструкция"),
("2", "Капитальный ремонт"),
("3", "Строительство"),
]
TYPE_CITY = [
("1", "Бронницы"),
("2", "Луховицы"),
("3", "Павловский Посад"),
("4", "Раменское"),
("5", "Шатура"),
]
class ArkiOneObject (models.Model):
city = models.CharField(
choices=TYPE_CITY,
verbose_name="Выберите ОМСУ")
typeobject = models.CharField(
choices=TYPE_OBJECT,
verbose_name="Выберите тип объекта")
typework = models.CharField(
choices=TYPE_WORK,
verbose_name="Выберите тип работ")
nameobject = models.OneToOneField(ArkiObject, verbose_name="Наименование объекта", on_delete=models.CASCADE)
from django import forms
from .models import *
class FormOne (forms.ModelForm):
class Meta:
model = ArkiOneObject
fields = "__all__"
class FormTwo (forms.ModelForm):
class Meta:
model = ArkiTwoObject
fields = "__all__"
class FormThree (forms.ModelForm):
class Meta:
model = ArkiObject
fields = "__all__"
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>title</title>
</head>
<body>
<div>
<form method="POST" class="post-form">
{% csrf_token %} {{formtwo.as_p}}
<button type="submit" class="button">Отправить</button>
</form>
</div>
</body>
</html>
def formone(request):
context = {}
formone = FormOne(request.POST or None)
if formone.is_valid():
formone.save()
return redirect("formone")
context['formone'] = formone
return render(request, "formone.html", context)
def formtwo(request):
context = {}
formtwo = FormTwo(request.POST or None)
if formtwo.is_valid():
formtwo.save()
return redirect("formtwo")
context['formtwo'] = formtwo
return render(request, "formtwo.html", context)
Unfortunately, standard HTML <select>
and <option>
elements do not support text wrapping by design — they are limited in terms of formatting. If the text is long, it will either overflow, be cut off, or require horizontal scrolling (depending on browser).
Use Select2
Libraries like Select2 replace the native select box with a stylable widget that supports multi-line text, search, and better UX.
Use Tooltips with Ellipsis (Not Wrapping)