python / beginner
Snippet
Creating a Django Model
Models are the single source of truth about your data. They contain the essential fields and behaviors of the data you're storing, mapped to database tables.
snippet.py
1
2
3
4
5
from django.db import modelsclass Task(models.Model):title = models.CharField(max_length=200)is_completed = models.BooleanField(default=False)
django
Breakdown
1
class Task(models.Model):
Defines a new class that inherits from Django's Model class.
2
title = models.CharField(max_length=200)
Creates a character field for text, limited to 200 characters.
3
is_completed = models.BooleanField(default=False)
Creates a true/false field that starts as false by default.