Index: django/contrib/admin/templates/admin/auth/user/delete_confirmation.html
===================================================================
--- django/contrib/admin/templates/admin/auth/user/delete_confirmation.html	(revision 0)
+++ django/contrib/admin/templates/admin/auth/user/delete_confirmation.html	(revision 0)
@@ -0,0 +1,11 @@
+{% extends "admin/delete_confirmation.html" %}
+{% load i18n %}
+
+{% block content %}
+{% ifequal user object %}
+<ul class="errorlist">
+	<li>{% trans "You are attempting to delete yourself" %}</li>
+</ul>
+{% endifequal %}
+{{block.super}}
+{% endblock %}
Index: django/contrib/auth/admin.py
===================================================================
--- django/contrib/auth/admin.py	(revision 9798)
+++ django/contrib/auth/admin.py	(working copy)
@@ -9,6 +9,7 @@
 from django.template import RequestContext
 from django.utils.html import escape
 from django.utils.translation import ugettext, ugettext_lazy as _
+from django.db import IntegrityError
 
 class GroupAdmin(admin.ModelAdmin):
     search_fields = ('name',)
@@ -124,7 +125,31 @@
             'root_path': self.admin_site.root_path,
         }, context_instance=RequestContext(request))
 
+    def log_deletion(self, request, object, object_repr):
+        """Do not log if the user being deleted is the logged in user - ticket #8159"""
+        
+        try:
+            super(UserAdmin, self).log_deletion(request, object, object_repr)
+        except IntegrityError, e:
+            self._raiseIfExists(e, request.user)
 
+    def message_user(self, request, message):
+        """Do not message if the user being deleted is the logged in user - ticket #8159"""
+        
+        try:
+            super(UserAdmin, self).message_user(request, message)
+        except IntegrityError, e:
+            self._raiseIfExists(e, request.user)
+
+    def _raiseIfExists(self, exception, user):
+        """Raises exception if user is in the db"""
+        
+        try:
+            User.objects.get(pk=user.id)
+            raise exception
+        except User.DoesNotExist:
+            pass
+
 admin.site.register(Group, GroupAdmin)
 admin.site.register(User, UserAdmin)
 
Index: tests/regressiontests/admin_views/urls_admin.py
===================================================================
--- tests/regressiontests/admin_views/urls_admin.py	(revision 0)
+++ tests/regressiontests/admin_views/urls_admin.py	(revision 0)
@@ -0,0 +1,7 @@
+from django.conf.urls.defaults import *
+from django.contrib import admin
+admin.autodiscover()
+
+urlpatterns = patterns('',
+    (r'^admin/(.*)', admin.site.root),
+)
Index: tests/regressiontests/admin_views/tests.py
===================================================================
--- tests/regressiontests/admin_views/tests.py	(revision 9798)
+++ tests/regressiontests/admin_views/tests.py	(working copy)
@@ -721,3 +721,53 @@
         self.failUnlessEqual(response.status_code, 200)
         response = self.client.post('/test_admin/admin/admin_views/book/1/delete/', delete_dict)
         self.assertRedirects(response, '/test_admin/admin/admin_views/book/')
+
+
+class DeleteSelfTest(TestCase):
+    """Tests an admin user deleting themselves. See ticket #8159"""
+    
+    fixtures = ['admin-views-users.xml']
+    urls = 'regressiontests.admin_views.urls_admin'
+
+    def test_delete_as_super(self):
+        """Tests that a superuser can delete themselves"""
+        
+        username = 'super'
+        
+        self.client.login(username=username, password='secret')
+
+        # We exist
+        try:
+            u = User.objects.get(username=username)
+        except User.DoesNotExist:
+            self.fail("User 'super' does not exist - it should be in the fixture")
+        
+        # We delete ourselves
+        response = self.client.post('/admin/auth/user/'+ str(u.id) +'/delete/', {'post': 'yes'})
+        self.assertRedirects(response, '/admin/auth/user/')
+
+        # We don't exist
+        try:
+            User.objects.get(username=username)
+            self.fail("User 'super' was not deleted correctly")
+        except User.DoesNotExist:
+            pass
+
+        self.client.logout()
+    
+    def test_delete_no_perms(self):
+        """Test that a user without permissions still cannot delete themselves"""
+        
+        username= 'adduser'
+        
+        self.client.login(username=username, password='secret')
+
+        # We exist
+        try:
+            u = User.objects.get(username=username)
+        except User.DoesNotExist:
+            self.fail("User 'super' does not exist - it should be in the fixture")
+        
+        # We delete ourselves
+        response = self.client.post('/admin/auth/user/'+ str(u.id) +'/delete/', {'post': 'yes'})
+        self.failUnlessEqual(response.status_code, 403)
