我正在努力了解它的用法super().从它的外观来看,可以创建两个子类,就好了.
我很想知道以下2个孩子班级之间的实际差异.
class Base(object):
def __init__(self):
print "Base created"
class ChildA(Base):
def __init__(self):
Base.__init__(self)
class ChildB(Base):
def __init__(self):
super(ChildB, self).__init__()
ChildA()
ChildB()
Run Code Online (Sandbox Code Playgroud) 在django.utils.functional.py:
for t in type(res).mro(): # <----- this
if t in self.__dispatch:
return self.__dispatch[t][funcname](res, *args, **kw)
Run Code Online (Sandbox Code Playgroud)
我不明白mro().它是做什么的,"mro"是什么意思?
是否有可能ModelForm在django中包含多个模型?我正在尝试创建个人资料编辑表单.所以我需要包含User模型和 UserProfile模型中的一些字段.目前我正在使用这样的2个表单
class UserEditForm(ModelForm):
class Meta:
model = User
fields = ("first_name", "last_name")
class UserProfileForm(ModelForm):
class Meta:
model = UserProfile
fields = ("middle_name", "home_phone", "work_phone", "cell_phone")
Run Code Online (Sandbox Code Playgroud)
有没有办法将这些整合到一个表单中,或者我只需要创建一个表单并处理数据库加载并保存自己?
class A:
def amethod(self): print("Base1")
class B():
def amethod(self): print("Base3")
class Derived(A,B):
pass
instance = Derived()
instance.amethod()
#Now i want to call B method amethod().. please let me know the way.**
Run Code Online (Sandbox Code Playgroud)
Python多重继承,调用第二个基类方法,如果两个基类都持有相同的方法