Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django model field for PostgreSQL NUMERIC data type

I'm using Django to create an application (using PostgreSQL) that needs a column numeric(15,6), but I'm not finding a method to do this.

like image 321
user8196 Avatar asked Sep 22 '15 15:09

user8196


1 Answers

From PostgreSQL docs:

The types decimal and numeric are equivalent. Both types are part of the SQL standard.

So you can use Django's DecimalField

class MyModel(models.Model):
    my_field = models.DecimalField(max_digits=15, decimal_places=6)

Some docs:

  • http://www.postgresql.org/docs/current/interactive/datatype-numeric.html#DATATYPE-NUMERIC-DECIMAL
  • https://docs.djangoproject.com/en/1.8/ref/forms/fields/#decimalfield
like image 103
bakkal Avatar answered Sep 20 '22 00:09

bakkal