本文整理汇总了Python中django.forms.ModelForm.save方法的典型用法代码示例。如果您正苦于以下问题:Python ModelForm.save方法的具体用法?Python ModelForm.save怎么用?Python ModelForm.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.forms.ModelForm
的用法示例。
在下文中一共展示了ModelForm.save方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save
# 需要导入模块: from django.forms import ModelForm [as 别名]
# 或者: from django.forms.ModelForm import save [as 别名]
def save(self):
if self.is_valid():
au = auth.models.User.objects.create_user(
username=self.cleaned_data["email"],
email=self.cleaned_data["email"],
password=self.cleaned_data["password"],
)
self.instance.user = au
self.instance.user.first_name = self.cleaned_data["first_name"]
self.instance.user.last_name = self.cleaned_data["last_name"]
self.instance.user.save()
ModelForm.save(self)
示例2: save
# 需要导入模块: from django.forms import ModelForm [as 别名]
# 或者: from django.forms.ModelForm import save [as 别名]
def save(self, commit=True):
# we want to bypass UserCreationForm's save.
user = ModelForm.save(self, commit=False)
# only set a pass if the form is filled
if self.cleaned_data['password1']:
user.set_password(self.cleaned_data["password1"])
if commit:
user.save()
return user
示例3: save
# 需要导入模块: from django.forms import ModelForm [as 别名]
# 或者: from django.forms.ModelForm import save [as 别名]
def save(self, commit=True):
# Get the saved Group instance
group = ModelForm.save(self, True)
GroupItem.objects.filter(group=group, item__wisher=self.user).delete()
group_items = []
for item in self.cleaned_data['items']:
print "creating intermediate groupitems[item] for %s" % item
group_items.append(GroupItem(group=group, item=item).save())
return group_items
示例4: save
# 需要导入模块: from django.forms import ModelForm [as 别名]
# 或者: from django.forms.ModelForm import save [as 别名]
def save(self, commit=True):
added_sites = set()
msc = ModelForm.save(self, commit)
for site in self.cleaned_data['active_sites']:
added_sites.add(site)
if msc.pk:
if set(added_sites) != set(msc.seosite_set.all()):
msc.seosite_set = added_sites
else:
msc.save()
msc.seosite_set = added_sites
return msc
示例5: save
# 需要导入模块: from django.forms import ModelForm [as 别名]
# 或者: from django.forms.ModelForm import save [as 别名]
def save(self, **args):
res = ModelForm.save(self, **args)
for f in FlagType.objects.all():
fv = self.data[f.name]
d = {'item': self.instance.id, 'type': f.id, 'value': fv}
try:
fg = Flag.objects.get(item=self.instance.id, type=f.id)
except Flag.DoesNotExist:
fg = Flag()
ff = FlagForm(d, instance=fg)
fv = ff.save()
setattr(res, f.name, fv)
return res
示例6: save
# 需要导入模块: from django.forms import ModelForm [as 别名]
# 或者: from django.forms.ModelForm import save [as 别名]
def save(self, commit=True):
# Get the unsaved Item instance
instance = ModelForm.save(self, False)
# Prepare a 'save_m2m' method for the form,
old_save_m2m = self.save_m2m
def new_save_m2m():
old_save_m2m()
# This is where we actually link the item with groups
instance.wishlistgroup_set.clear()
for group in self.cleaned_data['groups']:
print "creating intermediate groupitems for %s" % group
GroupItem(item=instance, group=group).save()
# instance.wishlistgroup_set.add(group)
self.save_m2m = new_save_m2m
# Do we need to save all changes now?
if commit:
instance.save()
self.save_m2m()
return instance
示例7: save
# 需要导入模块: from django.forms import ModelForm [as 别名]
# 或者: from django.forms.ModelForm import save [as 别名]
def save(self, *args, **kwargs):
inst = ModelForm.save(self, *args, **kwargs)
return inst
示例8: save
# 需要导入模块: from django.forms import ModelForm [as 别名]
# 或者: from django.forms.ModelForm import save [as 别名]
def save(self, *args, **kwargs):
inst = ModelForm.save(self, *args, **kwargs)
inst.item.item.save()
newIssueSignal.send(sender=inst, instance=inst, created =True, data=self.data)
return inst