7 examples of 'on_delete django' in Python

Every line of 'on_delete django' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
405def post_delete(sender, instance, **kwargs):
406 post(True, sender, instance, **kwargs)
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

199def post_delete(self):
200 if getattr(settings, 'NEOMODEL_SIGNALS', True):
201 signals.post_delete.send(sender=self.__class__, instance=self)
208def test_restrict_gfk_no_fast_delete(self):
209 delete_top = DeleteTop.objects.create()
210 generic_b1 = GenericB1.objects.create(generic_delete_top=delete_top)
211 generic_b2 = GenericB2.objects.create(generic_delete_top=delete_top)
212 GenericDeleteBottom.objects.create(generic_b1=generic_b1, generic_b2=generic_b2)
213 msg = (
214 "Cannot delete some instances of model 'GenericB1' because they "
215 "are referenced through a restricted foreign key: "
216 "'GenericDeleteBottom.generic_b1'."
217 )
218 with self.assertRaisesMessage(RestrictedError, msg):
219 generic_b1.delete()
220 self.assertTrue(DeleteTop.objects.exists())
221 self.assertTrue(GenericB1.objects.exists())
222 self.assertTrue(GenericB2.objects.exists())
223 self.assertTrue(GenericDeleteBottom.objects.exists())
224 # Object referenced also with CASCADE relationship can be deleted.
225 delete_top.delete()
226 self.assertFalse(DeleteTop.objects.exists())
227 self.assertFalse(GenericB1.objects.exists())
228 self.assertFalse(GenericB2.objects.exists())
229 self.assertFalse(GenericDeleteBottom.objects.exists())
298def delete(self, *args, **kwargs):
299 fields_after = self.form.fields.filter(order__gte=self.order)
300 fields_after.update(order=models.F("order") - 1)
301 super(Field, self).delete(*args, **kwargs)
87@receiver(post_delete)
88def on_post_delete(sender, **kwargs):
89 """Expire ultracache cache keys affected by this object
90 """
91 if not invalidate:
92 return
93 if kwargs.get("raw", False):
94 return
95 if sender is MigrationRecorder.Migration:
96 return
97 if issubclass(sender, Model):
98 obj = kwargs["instance"]
99 if isinstance(obj, Model):
100 # get_for_model itself is cached
101 try:
102 ct = ContentType.objects.get_for_model(sender)
103 except RuntimeError:
104 # This happens when ultracache is being used by another product
105 # during a test run.
106 return
107
108 # Expire cache keys
109 key = "ucache-%s-%s" % (ct.id, obj.pk)
110 to_delete = cache.get(key, [])
111 if to_delete:
112 try:
113 cache.delete_many(to_delete)
114 except NotImplementedError:
115 for k in to_delete:
116 cache.delete(k)
117 cache.delete(key)
118
119 # Invalidate paths in reverse caching proxy
120 key = "ucache-pth-%s-%s" % (ct.id, obj.pk)
121 if purger is not None:
122 for path in cache.get(key, []):
123 purger(path)
124 cache.delete(key)
99def delete(self, *args, **kwargs):
100 self._send_notify("delete")
101 return super().delete(*args, **kwargs)
417def pre_delete_tablejoin(instance, sender, **kwargs):
418 """
419 Remove the existing join in the database
420 """
421 instance.remove_joins()

Related snippets