18b887e2b51e53f73a4fd6f05d13bfadcc5e654e
[cas.git] / src / ssh_keys / models.py
1 from django.conf import settings
2 from django.db import models
3 from django.utils.translation import ugettext_lazy as _
4
5
6 class SSHKey(models.Model):
7     user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, verbose_name=_('user'))
8     key = models.TextField(_('key'))
9     comment = models.CharField(_('comment'), max_length=255, blank=True)
10     created_at = models.DateTimeField(_('created at'), auto_now_add=True)
11
12     class Meta:
13         ordering = ['created_at']
14         verbose_name = _('SSH key')
15         verbose_name_plural = _('SSH keys')
16
17     def __str__(self):
18         return self.comment
19
20     def save(self, *args, **kwargs):
21         self.comment = self.key.rsplit()[-1][:255]
22         return super().save(*args, **kwargs)