0 day streak
python / beginner
Snippet

Basic Django Model Fields

Django uses Model fields to define the structure of your database. CharField is for short text, while TextField is for longer content like descriptions.

snippet.py
python
1
2
3
4
5
from django.db import models
class Task(models.Model):
title = models.CharField(max_length=200)
description = models.TextField()
django
Breakdown
1
title = models.CharField(max_length=200)
Defines a short string field that requires a maximum length to be specified.
2
description = models.TextField()
Defines a field for large amounts of text without a strict character limit.