在Django 3.x框架中,模型字段用于定义数据库表中的列。以下是一些常见的模型字段类型及其用法:
from django.db import models
class MyModel(models.Model):
name = models.CharField(max_length=100)
from django.db import models
class MyModel(models.Model):
description = models.TextField()
from django.db import models
class MyModel(models.Model):
age = models.IntegerField()
from django.db import models
class MyModel(models.Model):
score = models.FloatField()
from django.db import models
class MyModel(models.Model):
birth_date = models.DateField()
from django.db import models
class MyModel(models.Model):
event_time = models.TimeField()
from django.db import models
class MyModel(models.Model):
created_at = models.DateTimeField()
这些只是一些常见的模型字段类型,Django还提供了许多其他字段类型,如布尔型字段(BooleanField)、文件型字段(FileField)等。您可以根据您的需求选择合适的字段类型来定义模型。