本文整理汇总了Python中django.views.generic.CreateView.form_valid方法的典型用法代码示例。如果您正苦于以下问题:Python CreateView.form_valid方法的具体用法?Python CreateView.form_valid怎么用?Python CreateView.form_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.views.generic.CreateView
的用法示例。
在下文中一共展示了CreateView.form_valid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: form_valid
# 需要导入模块: from django.views.generic import CreateView [as 别名]
# 或者: from django.views.generic.CreateView import form_valid [as 别名]
def form_valid(self, form):
thetime = timezone.now()
thetime = thetime.replace(hour=0, minute=0, second=0, microsecond=0)
universe = Universe(current_time=thetime, mode='Arcade')
universe.save()
form.instance.universe = universe
form.instance.created_igt = universe.current_time
form.instance.mode = "Arcade"
slug = slugify(form.instance.name)
retry = 1
while Enterprise.objects.filter(slug=slug).count() != 0:
slug = slugify(form.instance.name + ' ' + retry)
retry += 1
form.instance.slug = slug
response = CreateView.form_valid(self, form)
form.instance.owners.add(self.request.user)
action = ActionRecord(enterprise=form.instance, when_igt=universe.current_time,
description='Enterprise %s started' % form.instance.name)
action.save()
form.instance.add_transaction(details='Initial Investment',
acc_type='Equity', amount=form.instance.start_cash)
game.start_game(form.instance)
return response
示例2: form_valid
# 需要导入模块: from django.views.generic import CreateView [as 别名]
# 或者: from django.views.generic.CreateView import form_valid [as 别名]
def form_valid(self, form):
user_field = "%s_id" % self.get_user_field()
setattr(form.instance, user_field, self.request.user.id)
return CreateView.form_valid(self, form)