本文整理汇总了Python中django.db.models.Model.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Model.delete方法的具体用法?Python Model.delete怎么用?Python Model.delete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.db.models.Model
的用法示例。
在下文中一共展示了Model.delete方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: remove_stale_items
# 需要导入模块: from django.db.models import Model [as 别名]
# 或者: from django.db.models.Model import delete [as 别名]
def remove_stale_items(self, stale_cts):
"""
See if there are items that point to a removed model.
"""
stale_ct_ids = list(stale_cts.keys())
items = (ContentItem.objects
.non_polymorphic() # very important, or polymorphic skips them on fetching derived data
.filter(polymorphic_ctype__in=stale_ct_ids)
.order_by('polymorphic_ctype', 'pk')
)
if not items:
self.stdout.write("No stale items found.")
return
if self.dry_run:
self.stdout.write("The following content items are stale:")
else:
self.stdout.write("The following content items were stale:")
for item in items:
ct = stale_cts[item.polymorphic_ctype_id]
self.stdout.write("- #{id} points to removed {app_label}.{model}".format(
id=item.pk, app_label=ct.app_label, model=ct.model
))
if not self.dry_run:
try:
item.delete()
except PluginNotFound:
Model.delete(item)
示例2: handle
# 需要导入模块: from django.db.models import Model [as 别名]
# 或者: from django.db.models.Model import delete [as 别名]
def handle(self, *args, **options):
dry_run = options['dry_run']
#verbosity = options['verbosity']
stale_cts = {}
for ct in ContentType.objects.all():
if ct.model_class() is None:
stale_cts[ct.pk] = ct
items = (ContentItem.objects
.non_polymorphic() # very important, or polymorphic skips them on fetching derived data
.filter(polymorphic_ctype__in=list(stale_cts.keys()))
.order_by('polymorphic_ctype', 'pk')
)
if not items:
self.stdout.write("No stale items found.")
return
if dry_run:
self.stdout.write("The following content items are stale:")
else:
self.stdout.write("The following content items were stale:")
for item in items:
ct = stale_cts[item.polymorphic_ctype_id]
self.stdout.write("- #{id} points to removed {app_label}.{model}".format(id=item.pk, app_label=ct.app_label, model=ct.model))
if not dry_run:
try:
item.delete()
except PluginNotFound:
Model.delete(item)
示例3: remove_stale_pages
# 需要导入模块: from django.db.models import Model [as 别名]
# 或者: from django.db.models.Model import delete [as 别名]
def remove_stale_pages(self, stale_cts):
"""
See if there are items that point to a removed model.
"""
stale_ct_ids = list(stale_cts.keys())
pages = (UrlNode.objects
.non_polymorphic() # very important, or polymorphic skips them on fetching derived data
.filter(polymorphic_ctype__in=stale_ct_ids)
.order_by('polymorphic_ctype', 'pk')
)
if not pages:
self.stdout.write("No stale pages found.")
return
if self.dry_run:
self.stdout.write("The following pages are stale:")
else:
self.stdout.write("The following pages were stale:")
removed_pages = 0
for page in pages:
ct = stale_cts[page.polymorphic_ctype_id]
self.stdout.write("- #{id} points to removed {app_label}.{model}".format(
id=page.pk, app_label=ct.app_label, model=ct.model
))
if not self.dry_run:
try:
page.delete()
removed_pages += 1
except PageTypeNotFound:
Model.delete(page)
if removed_pages:
self.stdout.write("Note, when the removed pages contain content items, "
"also call `manage.py remove_stale_contentitems --remove-unreferenced")
示例4: delete
# 需要导入模块: from django.db.models import Model [as 别名]
# 或者: from django.db.models.Model import delete [as 别名]
def delete(self, no_mptt=False, *args, **kwargs):
if no_mptt:
Model.delete(self, *args, **kwargs)
else:
super(CMSPlugin, self).delete(*args, **kwargs)