From 28f324c64235a519e71489b24018efbc3b7a9c17 Mon Sep 17 00:00:00 2001 From: chirac Date: Fri, 1 Jul 2016 01:03:28 +0200 Subject: [PATCH] =?UTF-8?q?Corrige=20des=20bugs=20,=20change=20le=20type?= =?UTF-8?q?=20de=20etat=20=C3=A0=20integer,=20permet=20la=20creation=20d'u?= =?UTF-8?q?n=20user=20de=20mani=C3=A8re=20compl=C3=A8te?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- users/admin.py | 11 ++++++++++- users/models.py | 9 +++++++-- users/views.py | 9 +++++---- 3 files changed, 22 insertions(+), 7 deletions(-) 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)