![](/img/trans.png)
[英]django - int argument must be a string or a number, not 'Tuple'
[英]Django : int() argument must be a string or a number, not 'Plain'
我想我有一個相當簡單的問題。 但是我找不到解決方案。 自從我用python / django編寫以來已經有一段時間了...
我的簡單問題是,當我嘗試通過管理界面添加新的Plain時。
TypeError: int() argument must be a string or a number, not 'Plain'
具有表單的網站可以正確呈現,添加之前一切正常。
這是模型的代碼:
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)
當我嘗試添加Train或擴展Locomotion的任何其他類元素時,也會發生同樣的情況。
當您調用super
,您不需要傳遞self
:
super(Plain, self).__init__(*args, **kwargs)
另外,請注意,通常情況下,您要調用super
傳遞您從其調用的類,在這種情況下為Plain
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.