字段类型:
models.CharField
models.ForeignKey
models.DateTimeField
models.BinaryField
models.BooleanField
models.IPAddressField
models.IntegerField
models.FileField
models.ImageField
Meta:
class Meta: verbose_name = '用户留言信息' verbose_name_plural=verbose_name db_table = 'usermessage' ordering = 'object_id'
视图中添加数据到数据库:
1、create 一步到位
UserMessage.objects.create(name='yun',email='2@2.com',address='shanghai',message='nihao')
2、save 先创建模型实例,再设置字段值,最后保存
user_message = UserMessage() user_message.name = '天天' user_message.email = '3@3.com' user_message.address = '洛阳' user_message.message = '不错' user_message.save()
删除:
message.delete()