Automatic challenge creator user

This commit is contained in:
teras 2017-12-02 17:49:35 +02:00
parent c70e85342a
commit d0fac6602f
2 changed files with 12 additions and 2 deletions

View File

@ -2,6 +2,15 @@ from django.contrib import admin
from kspace.models import *
class ChallengeAdmin(admin.ModelAdmin):
list_display = ('name', 'description', 'creator',)
def save_model(self, request, obj, form, change):
if getattr(obj, 'creator', None) is None:
obj.creator = request.user
obj.save()
class InventoryItemAdmin(admin.ModelAdmin):
list_display = ('item_name', 'serial_nr', 'usable', 'owner', 'creator',)
@ -17,7 +26,8 @@ class InventoryItemLocationAdmin(admin.ModelAdmin):
class Media:
js = ('/static/admin/js/hide_attribute.js',)
admin.site.register(Challenge)
admin.site.register(Challenge, ChallengeAdmin)
admin.site.register(ChallengeTag)
admin.site.register(UserChallenge)
admin.site.register(Profile)

View File

@ -44,7 +44,7 @@ class ChallengeTag(models.Model):
class Challenge(models.Model):
id = models.AutoField(primary_key=True)
creator = models.ForeignKey(User)
creator = models.ForeignKey(User, blank=True, null=True, editable=False)
name = models.CharField(max_length=256)
description = models.TextField(blank=True)
tags = models.ManyToManyField(ChallengeTag, blank=True)