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


Python deletion.Collector方法代码示例

本文整理汇总了Python中django.db.models.deletion.Collector方法的典型用法代码示例。如果您正苦于以下问题:Python deletion.Collector方法的具体用法?Python deletion.Collector怎么用?Python deletion.Collector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.db.models.deletion的用法示例。


在下文中一共展示了deletion.Collector方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: delete

# 需要导入模块: from django.db.models import deletion [as 别名]
# 或者: from django.db.models.deletion import Collector [as 别名]
def delete(self):
        """
        Deletes the records in the current QuerySet.
        """
        assert self.query.can_filter(), \
            "Cannot use 'limit' or 'offset' with delete."

        del_query = self._clone()

        # The delete is actually 2 queries - one to find related objects,
        # and one to delete. Make sure that the discovery of related
        # objects is performed on the same database as the deletion.
        del_query._for_write = True

        # Disable non-supported fields.
        del_query.query.select_for_update = False
        del_query.query.select_related = False
        del_query.query.clear_ordering(force_empty=True)

        collector = Collector(using=del_query.db)
        collector.collect(del_query)
        collector.delete()

        # Clear the result cache, in case this QuerySet gets reused.
        self._result_cache = None 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:27,代码来源:query.py

示例2: setup_simple_attributes

# 需要导入模块: from django.db.models import deletion [as 别名]
# 或者: from django.db.models.deletion import Collector [as 别名]
def setup_simple_attributes(cls):
        for (attrname, default) in cls.simple_attributes:
            setattr(
                cls,
                attrname,
                property(
                    lambda self, attrname=attrname, default=default: self.get_attribute(
                        attrname, default
                    ),
                    lambda self, value, attrname=attrname: self.set_attribute(
                        attrname, value
                    ),
                    None,
                    attrname,
                ),
            )


# For cascading deletes, we need a Collector that doesn't do fastdelete,
# so we get a full list of models. 
开发者ID:open-cloud,项目名称:xos,代码行数:22,代码来源:xosbase_header.py

示例3: delete

# 需要导入模块: from django.db.models import deletion [as 别名]
# 或者: from django.db.models.deletion import Collector [as 别名]
def delete(self):
        """
        Deletes the records in the current QuerySet.
        """
        assert self.query.can_filter(), \
                "Cannot use 'limit' or 'offset' with delete."

        del_query = self._clone()

        # The delete is actually 2 queries - one to find related objects,
        # and one to delete. Make sure that the discovery of related
        # objects is performed on the same database as the deletion.
        del_query._for_write = True

        # Disable non-supported fields.
        del_query.query.select_for_update = False
        del_query.query.select_related = False
        del_query.query.clear_ordering(force_empty=True)

        collector = Collector(using=del_query.db)
        collector.collect(del_query)
        collector.delete()

        # Clear the result cache, in case this QuerySet gets reused.
        self._result_cache = None 
开发者ID:blackye,项目名称:luscan-devel,代码行数:27,代码来源:query.py

示例4: delete_without_cascade

# 需要导入模块: from django.db.models import deletion [as 别名]
# 或者: from django.db.models.deletion import Collector [as 别名]
def delete_without_cascade(self, using=None, keep_parents=False):
        """
        Modified version of django's default delete() method.

        This method is added to enable safe deletion of the child models without
        removing objects related to it through the parent. As of Feb 2017,
        no models are directly related to the OAuth2DataRequestProject or
        OnSiteDataRequestProject child models.
        """
        allowed_models = [
            "private_sharing.onsitedatarequestproject",
            "private_sharing.oauth2datarequestproject",
        ]
        if self._meta.label_lower not in allowed_models:
            raise Exception("'delete_without_cascade' only for child models!")
        using = using or router.db_for_write(self.__class__, instance=self)
        assert self._get_pk_val() is not None, (
            "%s object can't be deleted because its %s attribute is set to None."
            % (self._meta.object_name, self._meta.pk.attname)
        )

        collector = Collector(using=using)
        collector.collect([self], keep_parents=keep_parents, collect_related=False)
        return collector.delete() 
开发者ID:OpenHumans,项目名称:open-humans,代码行数:26,代码来源:models.py

示例5: delete

# 需要导入模块: from django.db.models import deletion [as 别名]
# 或者: from django.db.models.deletion import Collector [as 别名]
def delete(self, using=None):
        using = using or router.db_for_write(self.__class__, instance=self)
        assert self._get_pk_val() is not None, (
            "%s object can't be deleted because its %s attribute is set to None." %
            (self._meta.object_name, self._meta.pk.attname)
        )

        collector = Collector(using=using)
        collector.collect([self])
        collector.delete() 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:12,代码来源:base.py

示例6: as_sql

# 需要导入模块: from django.db.models import deletion [as 别名]
# 或者: from django.db.models.deletion import Collector [as 别名]
def as_sql(self):
        """ Generate SQL queries that perform related deletion """
        # List of (sql, params) tuples to perform deletion
        query_list = []

        for model, instances in self.data.items():
            self.data[model] = sorted(instances, key=attrgetter("pk"))
        self.sort()
        # Do not send pre_delete signals as in .delete()

        # Fast deletes
        for qs in self.fast_deletes:
            # TODO Check for any potential caveats from complex queries - assume none are generated by Collector

            # Clone queryset into DeleteQuery to use .as_sql()
            query_list.append(qs.query.clone(klass=sql.DeleteQuery).get_compiler(self.using).as_sql())

        # update fields
        for model, instances_for_fieldvalues in six.iteritems(self.field_updates):
            query = sql.UpdateQuery(model)
            for (field, value), instances in six.iteritems(instances_for_fieldvalues):
                query.add_update_values({field.name: value})
                query.add_q(models.Q(pk__in=[obj.pk for obj in instances]))
                query_list.append(query.get_compiler(using=self.using).as_sql())

        # reverse instance collections
        for instances in six.itervalues(self.data):
            instances.reverse()

        # delete instances
        for model, instances in six.iteritems(self.data):
            query = sql.DeleteQuery(model)
            pk_list = [obj.pk for obj in instances]
            query.where = query.where_class()
            query.add_q(models.Q(pk__in=pk_list))
            query_list.append(query.get_compiler(using=self.using).as_sql())

        # Do not update instances as in .delete()
        return query_list 
开发者ID:ashleywaite,项目名称:django-more,代码行数:41,代码来源:operations.py

示例7: delete

# 需要导入模块: from django.db.models import deletion [as 别名]
# 或者: from django.db.models.deletion import Collector [as 别名]
def delete(self, using=None, keep_parents=False):
        using = using or router.db_for_write(self.__class__, instance=self)
        assert self.pk is not None, (
            "%s object can't be deleted because its %s attribute is set to None." %
            (self._meta.object_name, self._meta.pk.attname)
        )

        collector = Collector(using=using)
        collector.collect([self], keep_parents=keep_parents)
        return collector.delete() 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:12,代码来源:base.py

示例8: delete

# 需要导入模块: from django.db.models import deletion [as 别名]
# 或者: from django.db.models.deletion import Collector [as 别名]
def delete(self):
        """Delete the records in the current QuerySet."""
        assert self.query.can_filter(), \
            "Cannot use 'limit' or 'offset' with delete."

        if self._fields is not None:
            raise TypeError("Cannot call delete() after .values() or .values_list()")

        del_query = self._chain()

        # The delete is actually 2 queries - one to find related objects,
        # and one to delete. Make sure that the discovery of related
        # objects is performed on the same database as the deletion.
        del_query._for_write = True

        # Disable non-supported fields.
        del_query.query.select_for_update = False
        del_query.query.select_related = False
        del_query.query.clear_ordering(force_empty=True)

        collector = Collector(using=del_query.db)
        collector.collect(del_query)
        deleted, _rows_count = collector.delete()

        # Clear the result cache, in case this QuerySet gets reused.
        self._result_cache = None
        return deleted, _rows_count 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:29,代码来源:query.py

示例9: _collect_related

# 需要导入模块: from django.db.models import deletion [as 别名]
# 或者: from django.db.models.deletion import Collector [as 别名]
def _collect_related(self, using=None, keep_parents=False):
        collector = Collector(using=using)
        collector.collect([self], keep_parents=keep_parents)
        fast_deletes = []
        for queryset in collector.fast_deletes:
            if queryset.count() > 0:
                fast_deletes.append(queryset)

        return dict(
            instances_with_model=collector.instances_with_model(), fast_deletes=fast_deletes, data=collector.data
        ) 
开发者ID:vigo,项目名称:django2-project-template,代码行数:13,代码来源:base.py

示例10: get_cascades

# 需要导入模块: from django.db.models import deletion [as 别名]
# 或者: from django.db.models.deletion import Collector [as 别名]
def get_cascades(self, user):
        c = Collector(user._state.db)
        c.collect([user])

        # figure out which models this user has data in
        existing = set(c.data.keys())
        existing.update(q.model for q in c.fast_deletes if q.exists())
        # but don't mention they have a User, that's obvious:
        existing.discard(User)
        return existing 
开发者ID:outreachy,项目名称:website,代码行数:12,代码来源:finddupemail.py

示例11: delete

# 需要导入模块: from django.db.models import deletion [as 别名]
# 或者: from django.db.models.deletion import Collector [as 别名]
def delete(self, using=None, keep_parents=False):
        using = using or router.db_for_write(self.__class__, instance=self)
        assert self._get_pk_val() is not None, (
            "%s object can't be deleted because its %s attribute is set to None." %
            (self._meta.object_name, self._meta.pk.attname)
        )

        collector = Collector(using=using)
        collector.collect([self], keep_parents=keep_parents)
        return collector.delete() 
开发者ID:Yeah-Kun,项目名称:python,代码行数:12,代码来源:base.py

示例12: delete

# 需要导入模块: from django.db.models import deletion [as 别名]
# 或者: from django.db.models.deletion import Collector [as 别名]
def delete(self):
        """
        Deletes the records in the current QuerySet.
        """
        assert self.query.can_filter(), \
            "Cannot use 'limit' or 'offset' with delete."

        if self._fields is not None:
            raise TypeError("Cannot call delete() after .values() or .values_list()")

        del_query = self._clone()

        # The delete is actually 2 queries - one to find related objects,
        # and one to delete. Make sure that the discovery of related
        # objects is performed on the same database as the deletion.
        del_query._for_write = True

        # Disable non-supported fields.
        del_query.query.select_for_update = False
        del_query.query.select_related = False
        del_query.query.clear_ordering(force_empty=True)

        collector = Collector(using=del_query.db)
        collector.collect(del_query)
        deleted, _rows_count = collector.delete()

        # Clear the result cache, in case this QuerySet gets reused.
        self._result_cache = None
        return deleted, _rows_count 
开发者ID:Yeah-Kun,项目名称:python,代码行数:31,代码来源:query.py

示例13: delete

# 需要导入模块: from django.db.models import deletion [as 别名]
# 或者: from django.db.models.deletion import Collector [as 别名]
def delete(self, *args, **kwargs):
        """
        Replace  super(BaseModel, self).delete()
        Cause: When delete relationship in cascade  default no have attribute User to Log.
        """

        using = router.db_for_write(self.__class__, instance=self)
        assert self._get_pk_val() is not None, "%s object can't be deleted because its %s attribute is set to None." % (
            self._meta.object_name, self._meta.pk.attname)

        collector = Collector(using=using)
        collector.collect([self])

        collector.delete() 
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:16,代码来源:BaseModel.py

示例14: delete

# 需要导入模块: from django.db.models import deletion [as 别名]
# 或者: from django.db.models.deletion import Collector [as 别名]
def delete(self, using=None):
        using = using or router.db_for_write(self.__class__, instance=self)
        assert self._get_pk_val() is not None, "%s object can't be deleted because its %s attribute is set to None." % (self._meta.object_name, self._meta.pk.attname)

        collector = Collector(using=using)
        collector.collect([self])
        collector.delete() 
开发者ID:blackye,项目名称:luscan-devel,代码行数:9,代码来源:base.py

示例15: modal_delete

# 需要导入模块: from django.db.models import deletion [as 别名]
# 或者: from django.db.models.deletion import Collector [as 别名]
def modal_delete(request, s, *args, **kwargs):
  server = Server.objects.get(id=s)

  collector = Collector(using='default')
  collector.collect([server])
  estimate = sum(len(x) for x in collector.data.values())

  breakdown = {}
  for k, v in collector.data.items():
    name = k._meta.verbose_name_plural if len(v) != 1 else k._meta.verbose_name
    breakdown[name] = len(v)

  return render(request, 'components/servers/detailed/modals/delete.pug',
                {'estimate': estimate,
                 'breakdown': breakdown}) 
开发者ID:indietyp,项目名称:hawthorne,代码行数:17,代码来源:server.py


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