diff --git a/home/templates/home/index.html b/home/templates/home/index.html index 0c668b2..e3685e4 100644 --- a/home/templates/home/index.html +++ b/home/templates/home/index.html @@ -7,6 +7,14 @@
{{ user.note }}
{% endif %} diff --git a/users/admin.py b/users/admin.py index 3966363..a4aaa84 100644 --- a/users/admin.py +++ b/users/admin.py @@ -1,12 +1,20 @@ from django.contrib import admin from django.contrib.auth.admin import UserAdmin as BaseUserAdmin -from .models import User +from .models import Key, User + + +class KeyInline(admin.TabularInline): + model = Key + extra = 1 class UserAdmin(BaseUserAdmin): fieldsets = BaseUserAdmin.fieldsets + ( ('Profile', {'fields': ('avatar', 'note')}), ) + inlines = ( + KeyInline, + ) admin.site.register(User, UserAdmin) diff --git a/users/migrations/0003_key.py b/users/migrations/0003_key.py new file mode 100644 index 0000000..c8e564a --- /dev/null +++ b/users/migrations/0003_key.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.6 on 2017-10-23 01:25 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0002_auto_20171023_0109'), + ] + + operations = [ + migrations.CreateModel( + name='Key', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('fingerprint', models.CharField(max_length=40)), + ('file', models.FileField(upload_to='keys')), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='keys', to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/users/models.py b/users/models.py index 55ec906..fcfadec 100644 --- a/users/models.py +++ b/users/models.py @@ -9,3 +9,16 @@ def avatar_path(instance, name): class User(AbstractUser): avatar = models.ImageField(upload_to=avatar_path) note = models.TextField(blank=True) + + +class Key(models.Model): + user = models.ForeignKey( + User, + related_name='keys', + on_delete=models.CASCADE + ) + fingerprint = models.CharField(max_length=40) + file = models.FileField(upload_to='keys') + + def pretty_print(self): + return " ".join(self.fingerprint[i:i+4] for i in range(0, 40, 4))