多個值,我得到一個類型錯誤:模型庫對象得到了關鍵字參數
在我的測試框架TypeError: ModelBase object got multiple values for keyword argument 'date'
當我嘗試創建一個「城市」。
這裏是我的回溯:
ERROR: test_create_city (app.tests.AppManagementTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "..tests.py", line 158, in test_create_city
city_obj = City(user = self.user, category = c, date = datetime.datetime.now(), **data)
TypeError: ModelBase object got multiple values for keyword argument 'date'
和我的代碼:
def test_create_city(self):
c = Category(name=self.categories[0]['name'])
c.save()
data = {'vehiclesound': '/assets/sounds/vehicle.ogg', 'vehicleshadow': '', 'maxspeed': 160.0, 'suspensionrestlength': 0.5, 'category': 12L, 'leftpub': '8294092164', 'wheelmodelzscale': 0.7, 'camheight': 2.1, 'speedminturn': 50.0, 'suspensiondeltatime': 0.25, 'crashsound': '/assets/sounds/crash.ogg', 'decel': 40.0, 'camtilt': 90.0, 'turnspeedmin': 20.0, 'path': 'just_testing_path', 'frontrightwheel': '', 'limitlinealpha': '01', 'open': 1, 'id': 35L, 'limitheight': 700L, 'modelzscale': 0.7, 'model_complete': 'http://youbeq.org/models/get.php?file=default_app/model.dae', 'rearleftwheel': '', 'user_id': 1L, 'wheelmodelyscale': 0.7, 'allwheels': 'http://sketchup.google.com/3dwarehouse/download?mid=4bc3b6056f5cd97eb5d8f6f0e9fb0ac&rtyp=ks&fn=taxi_4tires&ctyp=other&prevstart=0&ts=1343322996000', 'limitlinecolor': 'FFFFFF', 'limitcolor': '00ffff', 'gravity': 70.0, 'modelxscale': 0.7, 'limitlinewidth': 2L, 'kms': 9007.25, 'axisdistance': 2.5, 'minaccelstep': 5.0, 'wheelsdistance': 1.0, 'limitalpha': '70', 'turnspeedmax': 60.0, 'traildistance': 10.0, 'suspensionstiffness': 0.5, 'vehicletype': 'car', 'description': 'The City that never sleeps', 'wheelsheight': 0.37, 'vehiclesoundtime': 150.0, 'rollclamp': 50.0, 'accel': 5.0, 'backgroundsoundtime': 150.0, 'wheelmodelxscale': 0.7, 'rightpub': '5607834847', 'key': 'just_testing_key', 'accelstep': 25.0, 'date': None, 'world': 'earth', 'mapiconurl': '', 'vehicleagility': 0.0005, 'footer_large': '/assets/img/new_york.png', 'modelheight': 0.0, 'frontleftwheel': '', 'speedmaxturn': 5.0, 'name': 'New York', 'footer': '/taxi/assets/img/taxi_smarturbia_image_new_york.png', 'suspensiondamping': -0.15, 'rearrightwheel': '', 'crashsoundtime': 150.0, 'vehiclefastsoundtime': 150.0, 'maxrevspeed': 15.0, 'mass': 3000.0, 'backgroundsound': '/assets/sounds/background.ogg', 'published': 1, 'modelyscale': 0.7, 'model': 'http://sketchup.google.com/3dwarehouse/download?mid=128bf1862f1eb56db5d8f6f0e9fb0ac&rtyp=ks&fn=taxi_new_york_chassi&ctyp=other&prevstart=12&ts=1343297355000', 'vehiclefastsound': '', 'rollspring': 0.5, 'steerroll': -1.0}
print self.user
try :
city_obj = City.objects.get(key=self.categories[0]['name'])
print ("city_already_exists")
except City.DoesNotExist:
print ("debug")
city_obj = City(user = self.user, category = c, date = datetime.datetime.now(), **data)
city_obj.save()
謝謝你,雖然即時通訊仍然不知道第一次約會來自哪裏,因爲我複製粘貼從另一個代碼,只是工作..反正它的工作現在;) – psychok7 2013-03-20 15:08:43
我現在得到它,我發現問題是與你所說的沒有關係,而是與「footer_large」中的一個關鍵錯誤相關。這讓我的Python變得瘋狂。我現在可以離開我的上面的代碼,它的工作原理。但是我仍然會將你的答案標記爲正確的答案,因爲它適用於這個特定的案例 – psychok7 2013-03-20 15:23:13