X-Git-Url: https://git.mdrn.pl/cas.git/blobdiff_plain/5c901ee485c3abdf11dec71bdb7534f1f6a9eaa9..6fd60e2fd1d41332a19f4e37e2874c51b21f13df:/src/ssh_keys/models.py diff --git a/src/ssh_keys/models.py b/src/ssh_keys/models.py index 960a5ec..18b887e 100644 --- a/src/ssh_keys/models.py +++ b/src/ssh_keys/models.py @@ -1,11 +1,22 @@ from django.conf import settings from django.db import models +from django.utils.translation import ugettext_lazy as _ class SSHKey(models.Model): - user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) - key = models.TextField() - created_at = models.DateTimeField(auto_now_add=True) + user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, verbose_name=_('user')) + key = models.TextField(_('key')) + comment = models.CharField(_('comment'), max_length=255, blank=True) + created_at = models.DateTimeField(_('created at'), auto_now_add=True) class Meta: ordering = ['created_at'] + verbose_name = _('SSH key') + verbose_name_plural = _('SSH keys') + + def __str__(self): + return self.comment + + def save(self, *args, **kwargs): + self.comment = self.key.rsplit()[-1][:255] + return super().save(*args, **kwargs)