admin.py 607 Bytes
Newer Older
1
#~*~ coding: utf-8 ~*~
2 3
from django.contrib import admin
import models
4
import forms
5

6

7
class DigicodeAdmin(admin.ModelAdmin):
8
    form = forms.DigicodeForm
9
    exclude = ('date',)
10 11 12 13 14 15 16
    
    def get_form(self, request, obj=None, **kwargs):
        '''
        Récupère l'utilisateur courant et le met par défaut owner.
        '''
        form = super(DigicodeAdmin, self).get_form(request, obj, **kwargs)
        form.base_fields['owner'].initial = request.user
17
        form.base_fields['digits'].initial = models.Code.gen_random_code()
18
        return form
19

20

21
admin.site.register(models.Code, DigicodeAdmin)