简体   繁体   English

Django:int()参数必须是字符串或数字,而不是'Plain'

[英]Django : int() argument must be a string or a number, not 'Plain'

I have rather simple problem i guess. 我想我有一个相当简单的问题。 But i cant find a solution. 但是我找不到解决方案。 It's been a while since i was writing in python/django... 自从我用python / django编写以来已经有一段时间了...

My simple problem is, when im trying to add new Plain by admin interface. 我的简单问题是,当我尝试通过管理界面添加新的Plain时。

TypeError: int() argument must be a string or a number, not 'Plain'

Site with form is rendering correctly, everything is fine till adding... 具有表单的网站可以正确呈现,添加之前一切正常。

This is code of the models: 这是模型的代码:

class Locomotion(models.Model):
    transportation_firm_name = models.CharField(max_length=200)
    transportation_number =  models.CharField(max_length=200)
    departure_date_time =  models.DateTimeField()
    arrival_date_time =  models.DateTimeField()

    class Meta:
        abstract = True

    def __str__(self):
        return self.transportation_name


class Plain(Locomotion):
    seat_number  = models.CharField(max_length=200)
    class_section =  models.CharField(max_length=200)

    def __init__(self, *args, **kwargs):
        super(Locomotion, self).__init__(self, *args, **kwargs)

    def __str__(self):
        return "plain"


class Train(Locomotion):
    seat_number  = models.CharField(max_length=200)
    section_numbers =  models.CharField(max_length=200)

    def __init__(self, *args, **kwargs):
        super(Locomotion, self).__init__(self, *args, **kwargs)

And the same is happening when im trying to add Train or any other element of class extending Locomotion. 当我尝试添加Train或扩展Locomotion的任何其他类元素时,也会发生同样的情况。

When you call super , you don't need to pass self : 当您调用super ,您不需要传递self

super(Plain, self).__init__(*args, **kwargs)

Also, note that usually, you want to call super passing the class that you are calling it from, Plain in this case. 另外,请注意,通常情况下,您要调用super传递您从其调用的类,在这种情况下为Plain

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 django - int参数必须是字符串或数字,而不是'元组' - django - int argument must be a string or a number, not 'Tuple' Django int()参数必须是字符串或数字 - Django int() argument must be a string or a number int()参数必须是字符串或数字,而不是django中的'SimpleLazyObject' - int() argument must be a string or a number, not 'SimpleLazyObject' in django int() 参数必须是字符串或数字 - int() argument must be a string or a number Django-TypeError:int()参数必须是字符串或数字,而不是'dict' - Django - TypeError: int() argument must be a string or a number, not 'dict' 在django模型中保存datetimefiled,int()参数必须是字符串或数字 - saving datetimefiled in django models, int() argument must be a string or a number Django TypeError int()参数必须是字符串或数字,而不是'QueryDict' - Django TypeError int() argument must be a string or a number, not 'QueryDict' Django保存新记录,int()参数必须是字符串或数字,而不是'QueryDict' - Django Saving new record, int() argument must be a string or a number, not 'QueryDict' Django错误:TypeError:int()参数必须是字符串或数字,而不是“ BuildsTable” - Django Error: TypeError: int() argument must be a string or a number, not 'BuildsTable' Django Allauth-int()参数必须是字符串或数字,而不是'ReverseSingleRelatedObjectDescriptor' - Django Allauth - int() argument must be a string or a number, not 'ReverseSingleRelatedObjectDescriptor'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM