当前位置: 首页>>代码示例>>Python>>正文


Python Model.save方法代码示例

本文整理汇总了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)
开发者ID:xuhang57,项目名称:atmosphere,代码行数:9,代码来源:machine_request.py

示例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)
开发者ID:flesser,项目名称:OpenSlides,代码行数:37,代码来源:views.py

示例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'))
开发者ID:6aika,项目名称:issue-reporting,代码行数:9,代码来源:0005_geo_location.py

示例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
开发者ID:pombredanne,项目名称:dezede,代码行数:10,代码来源:utils.py

示例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)
开发者ID:berdario,项目名称:bdblog,代码行数:11,代码来源:models.py

示例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)
开发者ID:lucastx,项目名称:vestat,代码行数:53,代码来源:atualizar.py

示例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)
        
开发者ID:tjzhaomengyi,项目名称:pyinstruments,代码行数:18,代码来源:utilities.py

示例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)
开发者ID:Smarsh,项目名称:norc,代码行数:13,代码来源:daemon.py

示例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)
开发者ID:dmitry-krasilnikov,项目名称:model_mommy,代码行数:4,代码来源:mommy.py


注:本文中的django.db.models.Model.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。