Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create double and long text field from django models

How to create a double field in mysql using django models. i run into this error and also how to create a longtext datatype with django

class Test(models.Model):
   maxcount = models.DoubleField(null=True) ## double DEFAULT NULL,
   cs = models.TextField()#longtext,

Error:

    maxcount = models.DoubleField(null=True) ##double DEFAULT NULL,
    AttributeError: 'module' object has no attribute 'DoubleField'
like image 637
Rajeev Avatar asked Sep 11 '15 05:09

Rajeev


People also ask

What is the max length of TextField Django?

Django tip: Use models. TextField for storing long texts inside your models instead of models. CharField since CharField has a max length of 255 characters while TextField can hold more than 255 characters.

What is slug field in Django?

What is SlugField in Django? It is a way of generating a valid URL, generally using data already obtained. For instance, using the title of an article to generate a URL. Let's assume our blog have a post with the title 'The Django book by Geeksforgeeks' with primary key id= 2.

How do I merge two Django models?

1 Answer. Show activity on this post. In your models Device and History models are related with a foreign key from History to DeviceModel, this mean when you have a History object you can retrieve the Device model related to it, and viceversa (if you have a Device you can get its History).


1 Answers

There is no DoubleField in Django but FloatField [FloatField description in Django's Model field reference] creates a double datatype in mysql.

Django's TextField creates a LONGTEXT type in mysql. There is no easy way to change TextField behaviour to create e.g. MEDIUMTEXT type in mysql. But one can create a custom model field to achieve that: Writing custom model fields

like image 72
Andrey Grachev Avatar answered Sep 24 '22 11:09

Andrey Grachev