Hey Subodh,

If I your problem understood correctly, then `on_delete` option
available in ForeingKey field[1] should be helpful in this case.

As per docs, on_delete=models.PREVENT, prevents deletion of the
referenced object by raising ProtectedError, a subclass of
django.db.IntegrityError.

Links:
[1]: 
https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ForeignKey.on_delete

Pankaj Singh
http://about.me/psjinx


On Mon, Jan 21, 2013 at 12:42 AM, Subodh Nijsure
<[email protected]> wrote:
> Hi,
>
> Say I have model that comprises of Books and Authors. Where a book may have
> multiple authors and this has foreignkey in the books table.
>
> Now how do I prevent deletion of an author record while the there is record
> in books table that has pointer an author record (via foreign key).
>
> Do i need to do this via stored procedure/trigger on DB level or is there
> standard procedure to implement this in delete in django?
>
> Would appreciate any pointers.
>
> Regards,
> -Subodh
>
> --
> 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.

-- 
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