Is there any parameter to textField in model to remove '\r'

Hi,
In model, one of the column in postgres is text area. Do this

class Car(models.Model):
    car_id = models.PositiveBigIntegerField("Car Number", primary_key=True)
    car_description = models.TextField("Describe")

registered the model in admin. started creating records in admin page and it was observed that it was appended with ‘\r’ when i press enter in the text area.

postgres=# select * from car_model;
-[ RECORD 1 ]—±-------------------
car_id | 1234
car_description | This is old car.\r +
| Car number is 1234.
Is there any way not append ‘\r’ when press enter in the text area?

Hi,

\r is also called “carriage return” (CR) and is how new lines are represented in some operating systems (macOS typically). Other OSes can use \n (“line feed”) or even the combination of both \r\n.

Unfortunately there’s nothing in Django to normalize which character is used to represent a new line, so if that’s important for you you have to handle it yourself (using custom validation on the form for example).

It was proposed to add something at one point (9 years ago), but the idea was rejected: #19251 (Normalize newlines from Textarea widgets) – Django
Since then, Django did add the strip option (defaulting to True) that was also mentioned in this ticket, so maybe the idea of normalizing new lines would be received more positively today.

Also note that this is normally an invisible character. You’re only seeing it because of how you’re looking at the data.

If that data gets reloaded into the text area, you won’t see it, nor will you see it if you render that field as text within a page.

Thank you for quick for response.
To remove “\r” from the TextField, i used clean validator of the model.

def clean(self):
    self.car_description = self.car_description.replace("\r", "\n")

in database, it is saved as
postgres=# select * from car_model; -[ RECORD 1 ]—±-------------------
car_id | 1234
car_description | This is old car. +
| +
| Car number is 1234.
I want user readability. Therefore, i overwritten “\r” with “\n”. The side-effect is, introducing a new line in the database.
Is there any better approach to resolve this (user readability is the priority)?
Note: In actual use-case, i provide, SQL DDL statements. Here, i need user readability because of DDL statement after rendering from database to UI, i can not replace “\r” with " ".