Saving Output Accuracy with Django DecimalField and PostgreSql Numeric Field

I save data to the PostgreSQL backend via Django. Many of the fields in my DecimalFields models are set to arbitrarily high max_digits and decimal_places, corresponding to the numeric columns in the database backend. The data in each column has an accuracy (or the number of decimal places), which is unknown a priori, and each reference point in this column should not have the same accuracy.

For example, model arguments might look like this:

{'dist': Decimal("94.3"), 'dist_e': Decimal("1.2")}
{'dist': Decimal("117"), 'dist_e': Decimal("4")}

where the keys are the names of the database columns.

When I exit, I need to save and redisplay this data with the accuracy with which it was read. In other words, after querying the database, the displayed data should look exactly like the data that was read, with no additional or missing end 0 in decimal places. When requested, however, either in the django shell or in the admin interface, all DecimalField data is returned with many final 0s.

I saw similar questions that were answered in monetary terms, where the accuracy (2 decimal places) is known and the same for all the data in this column. However, what is the best way to preserve the exact precision represented by decimal values ​​in Django and numeric values ​​in PostgreSQL when the precision is not the same and unknown in advance?

EDIT:

, : , dbshell Django, 0. python, -, , models.py, PostgreSQL.

+5
2

, CharField. , . , , , CharField . (1000, 2000 ..), , TextField.

. , ( ), .

+1

, , , , - . Django PostgreSQL Numerical . , , , , , python, .

, , . 4.350 3 . (, 2531) 0. , , , . , 4.320E+33 -3. , .

, , . , / .

+1

All Articles