In my model structure there are two models.

```
class Message(models.Model)
    #there are some fields
    #...
    user = models.ForeignKey('User')

class User(models.Model)
    # and there

```

We can see that user `has many` messages, when user is deleted, all messages are deleted too, or foreign key is set to null.

The question is, how can i handle last user's message deleting event?
I need doing just something like this on every message deleting?

```
#...
if user.message_set.count() < 1:
    user.handle_last_message_delete()

```

Are there SQL-level solutions(as far as i know, triggers can help, but I'm not sure)?

If there are, what about django ORM compability?

And what solution would you choose, if message adding is much more frequent operation then deleting, and only admins are permitted to delete messages?

P.S. Great thanks in advance.

P.P.S. I also will be very thankful for relational databases theory links.