我正在django 1.9中使用基于类的视图,并且试图找出如何在不使用表单的情况下更新对象(单击按钮后)。我不需要任何用户输入即可更新对象。你能帮我吗?
在models.py
中class State(models.Model):
stateID = models.SmallIntegerField(primary_key=True)
isOpen = models.BooleanField(default=True, help_text='Designates whether the registration is open.', verbose_name='active')
def __unicode__(self):
return bool(self.isOpen)
在views.py
class OpenTournament(View):
model = State
def get(self, request, *args, **kwargs):
queryset = State.objects.all()
if queryset.count() != 1:
State(stateID=1, isOpen=True).save()
return HttpResponseRedirect('/success_url/')
else:
#need to update the table from a button click
return HttpResponseRedirect("/updated/")
答案 0 :(得分:0)
是的。我找到了。通过主键访问状态
ws.query("C:/ProgramData/Microsoft/Windows/Start Menu/Windows Update.lnk", console.log);
/* From console:
null { expanded:
{ args: 'startmenu',
workingDir: 'C:\\Windows\\system32',
icon: 'C:\\Windows\\system32\\wucltux.dll' },
target: '%windir%\\system32\\wuapp.exe',
args: 'startmenu',
workingDir: '%windir%\\system32',
runStyle: 1,
icon: '%windir%\\system32\\wucltux.dll',
iconIndex: '0',
hotkey: 0,
desc: 'Delivers software updates and drivers, and provides automatic updating options.' }
*/