调用LocationDescription.l\u edit返回错误“save()获得意外的关键字参数”“location”“。”。关键字名称看起来是随机的,可能在不同的时间指向不同的字段。方法l\u edit被剥夺了功能,但错误仍然存在。奇怪的是,自我定位=kwargs[“位置”]后跟自我保存()效果很好。在
在模型.py在
class LocationDescription(models.Model):
location = models.ForeignKey(Location)
description = models.ForeignKey(Localization)
YEAR_CHOICES = (
(LocationDescriptionYear.any.value, 'Any'),
(LocationDescriptionYear.winter.value, 'Winter'),
(LocationDescriptionYear.spring.value, 'Spring'),
(LocationDescriptionYear.summer.value, 'Summer'),
(LocationDescriptionYear.autumn.value, 'Autumn'),
)
year = models.IntegerField(choices=YEAR_CHOICES, default=0)
DAY_CHOICES = (
(LocationDescriptionDaytime.any.value, 'Any'),
(LocationDescriptionDaytime.night.value, 'Night'),
(LocationDescriptionDaytime.morning.value, 'Morning'),
(LocationDescriptionDaytime.day.value, 'Day'),
(LocationDescriptionDaytime.evening.value, 'Evening'),
)
day = models.IntegerField(choices=DAY_CHOICES, default=0)
weather_type = models.ForeignKey('Weather', blank=True, null=True)
order = models.IntegerField(default=0)
code_check = models.TextField(blank=True, null=True)
@classmethod
def l_create(cls, request, **kwargs):
l = Localization()
l.write(request, kwargs['description'])
kwargs['description'] = l
item = cls(**kwargs)
item.save()
return item
def l_delete(self):
l = self.description
self.delete()
l.delete()
def l_edit(self, **kwargs):
super(LocationDescription, self).save(**kwargs)
@classmethod
def localize(cls, locale, **kwargs):
if locale == 'eng':
result = cls.objects.filter(**kwargs).annotate(text=F('description__eng'))
elif locale == 'rus':
result = cls.objects.filter(**kwargs).annotate(text=F('description__rus'))
else:
raise KeyError
for r in result:
if r.text is None or r.text == '':
setattr(r, 'text', 'Error: localization text missing!')
return result
在视图.py在
^{pr2}$
save
不需要您传递的那些命名参数。此外,由于您没有重写默认的save
方法,所以我认为没有必要使用super
。在您只需在模型的那个实例上设置这些属性,然后用一个model对象调用
save
另外,如果不需要在内存中使用} 比当前的方法更有效。在
item
,那么使用^{相关问题 更多 >
编程相关推荐