Last modified: Jan 10, 2023 By Alexander Williams

How to Use Django models.TextField with Examples

Example 1


class MemEvents(models.Model):

    year = models.TextField()
    month = models.TextField()
    day = models.TextField()
    timestamp = models.TextField()
    err_msg = models.TextField()
    err_type = models.TextField()
    dev_id = models.IntegerField()
    evt_id = models.IntegerField()
    detail = models.TextField()
    evt_level = models.TextField()

Example 2


class Post(models.Model):                                             # class that will represent our database
    title = models.CharField(max_length=100)
    deadline=models.TextField(blank=True)
    customer = models.TextField(blank=True)
    pro = models.TextField(blank=True)
    goals = models.TextField(blank=True)
    problems = models.TextField(blank=True)
    connection = models.TextField(blank=True)
    yearly_work_plan = models.TextField(blank=True)
    cost_and_prodactivity = models.TextField(blank=True)

Example 3


class Comment(models.Model):
    post = models.ForeignKey('project.Post', on_delete=models.CASCADE, related_name='comments')
    author = models.CharField(max_length=200)
    text = models.TextField()
    created_date = models.DateTimeField(default=timezone.now)
    approved_comment = models.BooleanField(default=False)

Example 4


class EmailTemplate(models.Model):
    content = models.TextField()
    status = models.BooleanField(default=True)
    isDeleted = models.BooleanField(default="False")
    date = models.DateTimeField(auto_now_add=True)

Example 5


class AvaBcfCdr(models.Model):
    stime = models.DateTimeField(blank=True, null=True)
    ocgpn = models.DecimalField(max_digits=65535, decimal_places=0, blank=True, null=True)
    ocdpn = models.DecimalField(max_digits=65535, decimal_places=0, blank=True, null=True)
    s_trunk = models.TextField(blank=True, null=True)
    d_trunk = models.TextField(blank=True, null=True)
    duration = models.FloatField(blank=True, null=True)

Example 6


class CMS(models.Model):
    heading = models.TextField()
    content = models.TextField()
    status = models.BooleanField(default=True)
    isDeleted = models.BooleanField(default=False)
    date = models.DateTimeField(auto_now_add=True)