On Thursday 24 March 2011 20:46:12 pbzRPA wrote: > Hi, > > I am constantly running in a brick wall when it comes to deleting > records in Django. If you have one or two foreign keys it is easy to > check if they are in use, but once an application starts getting big > you can not remember which models are making use of a foreign key and > if a specific foreign key is in use. > > So my question: Is there a way to check if a single model record if > being used as a foreign key in all the models in a django project? For > example: > > class Stage(models.Model): > description = mo..... > > class Document(models,Model): > stage = models.ForeignKey(Stage) > > class Server(models.Model): > stage = models.ForeignKey(Stage) > > Now when I do "stage = Stage.objects.get(pk=x)" is it possible for me > to do some like "stage.?" and get back true or false if "stage" is > being used either in Document or Server or any other class that uses > Stage as a foreign Key but also only for this 1 specific record. > > All I really want to do is see if I can delete "stage" without it > effecting and other records in the database.
And if you're lucky and running 1.3 version you have new option on on_delete actions that can do it autogically. -- Jani Tiainen -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.