Django (fields.W340) null has no effect on ManyToManyField.
Model定义
python
class Customer(models.Model):
name = models.CharField(verbose_name='客户名', max_length=128)
contact = models.CharField(verbose_name='电话', max_length=11)
address = models.CharField(verbose_name='地址', max_length=128)
status_choices = (
(0, '意向客户'),
(3, '已报价'),
(1, '已拿样'),
(2, '已成交')
)
status = models.IntegerField(choices=status_choices, verbose_name='状态')
company = models.CharField(verbose_name='公司名', max_length=128, null=True, blank=True)
create_time = models.DateField(verbose_name='创建时间', auto_now=True)
product = models.ManyToManyField(Product, verbose_name='意向产品',null=True, blank=True)
description = models.TextField(verbose_name='备注', null=True, blank=True)
class Customer(models.Model):
name = models.CharField(verbose_name='客户名', max_length=128)
contact = models.CharField(verbose_name='电话', max_length=11)
address = models.CharField(verbose_name='地址', max_length=128)
status_choices = (
(0, '意向客户'),
(3, '已报价'),
(1, '已拿样'),
(2, '已成交')
)
status = models.IntegerField(choices=status_choices, verbose_name='状态')
company = models.CharField(verbose_name='公司名', max_length=128, null=True, blank=True)
create_time = models.DateField(verbose_name='创建时间', auto_now=True)
product = models.ManyToManyField(Product, verbose_name='意向产品',null=True, blank=True)
description = models.TextField(verbose_name='备注', null=True, blank=True)
警告信息
shell
(fields.W340) null has no effect on ManyToManyField.
(fields.W340) null has no effect on ManyToManyField.
解决办法
这只是一个小小的警告,可以不用处理,如果觉得碍眼,可以把product
字段的null=True移除
移除后就是这样的:
python
product = models.ManyToManyField(Product, verbose_name='意向产品', blank=True)
product = models.ManyToManyField(Product, verbose_name='意向产品', blank=True)
重启后,警告就消失了。