diff --git a/users/admin.py b/users/admin.py index 8c38f3f3..6e6adefd 100644 --- a/users/admin.py +++ b/users/admin.py @@ -1,3 +1,12 @@ from django.contrib import admin -# Register your models here. +from .models import User, School + +class UserAdmin(admin.ModelAdmin): + list_display = ('name','surname','pseudo','email', 'school', 'state') + +class SchoolAdmin(admin.ModelAdmin): + list_display = ('name',) + +admin.site.register(User, UserAdmin) +admin.site.register(School, SchoolAdmin) diff --git a/users/models.py b/users/models.py index 03b3bbcf..9ce74b04 100644 --- a/users/models.py +++ b/users/models.py @@ -13,19 +13,24 @@ class User(models.Model): name = models.CharField(max_length=255) surname = models.CharField(max_length=255) - pseudo = models.CharField(max_length=255) + pseudo = models.CharField(max_length=255, unique=True) email = models.EmailField() school = models.ForeignKey('School', on_delete=models.PROTECT) promo = models.CharField(max_length=255) pwd_ssha = models.CharField(max_length=255) pwd_ntlm = models.CharField(max_length=255) #location = models.ForeignKey('Location', on_delete=models.SET_DEFAULT) - state = models.CharField(max_length=30, choices=STATES, default=STATE_ACTIVE) + state = models.IntegerField(choices=STATES, default=STATE_ACTIVE) + def __str__(self): + return self.name class School(models.Model): name = models.CharField(max_length=255) + def __str__(self): + return self.name + class UserForm(ModelForm): class Meta: model = User diff --git a/users/views.py b/users/views.py index 2f3a30e4..4f9b738f 100644 --- a/users/views.py +++ b/users/views.py @@ -6,7 +6,7 @@ from django.shortcuts import render_to_response, get_object_or_404 from django.core.context_processors import csrf from django.template import Context, RequestContext, loader -from users.models import UserForm +from users.models import UserForm, InfoForm def form(ctx, template, request): @@ -16,9 +16,10 @@ def form(ctx, template, request): def new_user(request): if request.method == 'POST': - user = UserForm(request.Post) + user = InfoForm(request.POST) if user.is_valid(): user.save() - else: - user = UserForm() + return form({'userform': user}, 'users/new_user.html', request) + else: + user = InfoForm() return form({'userform': user}, 'users/new_user.html', request)