Here is a DRY preserving hack for models.py to implement CASCADE
RESTRICT in django:

# START models.py DRY hack for restricted cascade
#
# Where you wish to restrict the cascade: put the word "restrict" into
the related_name property of the ForeignKey field
# e.g.
#
#   nl_group = models.ForeignKey(Nlgroup,
related_name='nlmembersrestrict')
#
# Then add the following delete method to all the classes in your
model, replacing CLASSNAME with the name of the class
# ...
# def delete(self):
#   if not restricteddependents(self):
#     super(CLASSNAME, self).delete() # Call the "real" delete()
method
# ...
#
# Then add this function to the top of models.py  It will return the
number of
# restricted dependent records that are attached to this record.
#
def restricteddependents(InstanceObject):
  restricteddependents = 0
  for x in dir(InstanceObject):
    if x.count('restrict'):
      restricteddependents = restricteddependents +
InstanceObject.__getattribute__(x).count()
  return restricteddependents
# the admin interface still allows you to request deletion, but
nothing is actually deleted!
# END models.py DRY hack for restricted cascade


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to