本文整理汇总了Python中django.db.models.Model.save方法的典型用法代码示例。如果您正苦于以下问题:Python Model.save方法的具体用法?Python Model.save怎么用?Python Model.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.db.models.Model
的用法示例。
在下文中一共展示了Model.save方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save
# 需要导入模块: from django.db.models import Model [as 别名]
# 或者: from django.db.models.Model import save [as 别名]
def save(self, *args, **kwargs):
if not self.pk and self.is_active(self.instance):
raise RequestLimitExceeded(
"The number of open requests for "
"instance %s has been exceeded."
% self.instance.provider_alias)
Model.save(self, *args, **kwargs)
示例2: post
# 需要导入模块: from django.db.models import Model [as 别名]
# 或者: from django.db.models.Model import save [as 别名]
def post(self, request, *args, **kwargs):
if not request.user.has_perm('agenda.can_manage_agenda'):
messages.error(
request,
_('You are not authorized to manage the agenda.'))
context = self.get_context_data(**kwargs)
return self.render_to_response(context)
transaction.commit()
for item in Item.objects.all():
form = ItemOrderForm(request.POST, prefix="i%d" % item.id)
if form.is_valid():
try:
parent = Item.objects.get(id=form.cleaned_data['parent'])
except Item.DoesNotExist:
parent = None
item.weight = form.cleaned_data['weight']
item.parent = parent
Model.save(item)
else:
transaction.rollback()
messages.error(
request, _('Errors when reordering of the agenda'))
break
else:
Item.objects.rebuild()
# TODO: assure, that it is a valid tree
context = self.get_context_data(**kwargs)
transaction.commit()
if get_active_slide()['callback'] == 'agenda':
update_projector()
context = self.get_context_data(**kwargs)
transaction.commit()
return self.render_to_response(context)
示例3: recache_lat_long
# 需要导入模块: from django.db.models import Model [as 别名]
# 或者: from django.db.models.Model import save [as 别名]
def recache_lat_long(apps, schema_editor):
from issues.models import Issue as CurrentIssue
Issue = apps.get_model('issues', 'Issue')
for issue in Issue.objects.filter(location__isnull=False):
issue._cache_location = CurrentIssue._cache_location
issue._cache_location()
Model.save(self=issue, update_fields=('lat', 'long'))
示例4: enlarged_create
# 需要导入模块: from django.db.models import Model [as 别名]
# 或者: from django.db.models.Model import save [as 别名]
def enlarged_create(Model, filter_kwargs, commit=True):
filter_kwargs, m2m_kwargs = separate_m2m_kwargs(Model, filter_kwargs)
obj = Model(**filter_kwargs)
if commit:
obj.save()
for k, v in m2m_kwargs.items():
getattr(obj, k).add(*v)
return obj
示例5: save
# 需要导入模块: from django.db.models import Model [as 别名]
# 或者: from django.db.models.Model import save [as 别名]
def save(self, *args, **kwargs):
self.ascii_tag = unidecode(self.tag)
words = self.ascii_tag.split()
known_words_list = known_words(words)
for word in words:
new_word = Word(word)
if not new_word in known_words_list:
new_word.save()
Model.save(self, *args, **kwargs)
示例6: versao_1_2_2
# 需要导入模块: from django.db.models import Model [as 别名]
# 或者: from django.db.models.Model import save [as 别名]
def versao_1_2_2(cmd, *args):
"""
Atualizações pra versão 1.2.2.
Deve ser chamada após exportar o banco de dados pra um arquivo de
dump JSON e remover o arquivo do banco de dados.
Ações:
- Cria um novo banco de dados e o superusuário padrão
- Faz as conversões necessárias sobre o dump nos modelos que mudaram
- Importa o dump convertido pro banco de dados
- Carrega fixture de feriados bancários
Argumentos da linha de comando:
- dump_file: arquivo de dump do banco de dados na versão
1.2.1
"""
if len(args) != 1:
raise CommandError("Uso: atualizar 1.2.2 <dump_file>\n\ndump: arquivo de dump do banco de dados anterior (JSON)")
sync_and_evolve()
criar_superusuario()
print("Convertendo entradas no modelo antigo pro novo modelo...")
novo_bd_json = converter(args[0])
tmp_dump_filename = "fixture_convertida.json"
print("Armazenando dados convertidos em {tmp_dump_filename}".format(**vars()))
with open(tmp_dump_filename, "w") as tmp_dump_file:
tmp_dump_file.write(novo_bd_json)
print("Carregando dados convertidos no banco de dados...")
call_command("loaddata", tmp_dump_filename)
print("Removendo arquivo temporário...")
os.remove(tmp_dump_filename)
print("Carregando fixture de feriados bancários...")
call_command("loaddata", "feriados_bancarios")
print("Reunindo arquivos estáticos...")
call_command("collectstatic", interactive=False)
print("Re-salvando os pagamentos com cartões pra preencher data de depósito")
for pagamento in PagamentoComCartao.objects.all():
pagamento.data_do_deposito = pagamento._data_do_deposito()
Model.save(pagamento)
示例7: rename_all_files
# 需要导入模块: from django.db.models import Model [as 别名]
# 或者: from django.db.models.Model import save [as 别名]
def rename_all_files():
"""
Rename the data files according to the scheme:
yyyy/mm/dd/id.h5
"""
for curve in CurveDB.objects.all():
full_name_old = curve.get_full_filename()
new_name = osp.join(
curve.params["date"].strftime('%Y/%m/%d'),
str(curve.id) + '.h5')
curve.data_file = new_name
if not osp.exists(full_name_old):
print 'file ' + full_name_old + " doesn't exist"
else:
shutil.move(full_name_old, curve.get_full_filename())
Model.save(curve)
示例8: save
# 需要导入模块: from django.db.models import Model [as 别名]
# 或者: from django.db.models.Model import save [as 别名]
def save(self, *args, **kwargs):
"""Overwrites Model.save().
We have to be very careful to never overwrite a request, so
often the request must be read from the database prior to saving.
The safe parameter being set to True enables this behavior.
"""
if kwargs.pop('safe', False):
self.request = type(self).objects.get(id=self.id).request
return Model.save(self, *args, **kwargs)
示例9: _django_save
# 需要导入模块: from django.db.models import Model [as 别名]
# 或者: from django.db.models.Model import save [as 别名]
def _django_save(self, *args, **kwargs):
return Model.save(self, *args, **kwargs)