class AuditEntry(models.Model):
    action = models.CharField(max_length=64)
ip = models.GenericIPAddressField(null=True)
username = models.CharField(max_length=256, null=True)

def __unicode__(self):
    return '{0} - {1} - {2}'.format(self.action, self.username, self.ip)

@receiver(user_logged_in)
def user_logged_in_callback(sender, request, user, **kwargs):
    ip = request.META.get('REMOTE_ADDR')
How can I log both successful and failed login and logout attempts in Django?