You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
from django . db import models
from django . core . validators import MinValueValidator
# Create your models here.
class Medicine ( models . Model ) :
name = models . CharField ( max_length = 100 , verbose_name = ' 药品名称 ' )
description = models . TextField ( null = True , blank = True , verbose_name = ' 药品描述 ' )
# 为价格字段添加验证器, 确保价格不低于0
price = models . DecimalField (
max_digits = 10 ,
decimal_places = 2 ,
verbose_name = ' 价格 ' ,
validators = [ MinValueValidator ( 0 ) ]
)
# 为库存数量字段添加验证器, 确保库存数量不低于0
stock = models . IntegerField (
default = 0 ,
verbose_name = ' 库存数量 ' ,
validators = [ MinValueValidator ( 0 ) ]
)
def __str__ ( self ) :
return self . name
class Meta :
verbose_name = ' 药品 '
verbose_name_plural = verbose_name
class Admin ( models . Model ) :
""" 管理员 """
username = models . CharField ( verbose_name = " 用户名 " , max_length = 32 )
password = models . CharField ( verbose_name = " 密码 " , max_length = 64 )
def __str__ ( self ) :
return self . username