0
我想用我自己的'snAccount'類來擴展名爲'Account'(來自django-user-accounts應用)的類,因爲我需要爲每個用戶添加一些額外的字段帳戶。問題是當我嘗試覆蓋「工廠」的方法父類(@classmethod)與我:Overriden @classmethod,輸入異常
# Original method
@classmethod
def create(cls, request=None, **kwargs):
...
...
# Override attempt
@classmethod
def create(cls, request=None, **kwargs):
create_email = kwargs.pop("create_email", True)
user = kwargs.pop("user", None)
acc = Account.create(request, user, create_email)
x_account = cls(account, **kwargs)
x_account.save()
return x_account
這個問題我已經拋出了以下異常:
Django Version: 1.4.5
Exception Type: TypeError
Exception Value: create() takes at most 2 arguments (4 given)
Exception Location: /home/.../WebServices/models.py in create, line 27
...這是我無法理解的,因爲該方法的定義需要2個隱含的參數和** kwargs。我究竟做錯了什麼?我沒有太多的Python經驗,你可能會看到...