[英]How to use the value of a model in another value of the same django model
I have a model Group that has a field maximum_capacity and a member field, what i want to do is to use the value the user enters in the field maximum capacity to set the max_choices for the member field. 我有一个模型组,该模型组具有一个字段maximum_capacity和一个成员字段,我要做的是使用用户在该字段的最大容量中输入的值来为该成员字段设置max_choices。
I am using Django2.2 and the max_choices option came from the MutiSelectField package i installed. 我正在使用Django2.2,max_choices选项来自我安装的MutiSelectField软件包。 I have tried converting to int using int() but gives the same error.
我尝试使用int()转换为int,但给出了相同的错误。
class Group(models.Model):
number_of_group_members = ((i, i) for i in range(2, 100))
members_choices = [(member.email, member.first_name + member.last_name)
for member in CustomUser.objects.all()]
maximum_capacity = models.IntegerField(choices=number_of_group_members,
default='Specify group limit')
members = MultiSelectField(max_choices=(i for i in
range(maximum_capacity)), unique=True, choices=members_choices)
I keep getting the Error: 我不断收到错误消息:
members = MultiSelectField(max_choices=(i for i in range(maximum_capacity)),
TypeError: 'IntegerField' object cannot be interpreted as an integer
One problem here may be be that your IntegerField
default is a string value and that string could be causing trouble. 这里的一个问题可能是您的
IntegerField
默认值是一个字符串值,并且该字符串可能会引起麻烦。 Anyway, to help you properly you should post more code. 无论如何,为了正确帮助您,您应该发布更多代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.