From 142caf82d5f65d606d6f4cdd71ccd3774e8c8e6c Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Wed, 16 Jul 2014 14:16:19 +0200 Subject: [PATCH] models: AttributeRelease.attribute_name must not be contrained at the model level --- authentic2_idp_oauth2/admin.py | 20 +++++++++++++------- authentic2_idp_oauth2/models.py | 3 +-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/authentic2_idp_oauth2/admin.py b/authentic2_idp_oauth2/admin.py index 732d9a7..6cb36c5 100644 --- a/authentic2_idp_oauth2/admin.py +++ b/authentic2_idp_oauth2/admin.py @@ -1,5 +1,6 @@ from django.utils.translation import ugettext_lazy as _ from django.contrib import admin +from django import forms from authentic2.decorators import to_iter from authentic2.attributes_ng.engine import get_attribute_names @@ -10,15 +11,20 @@ from . import models class WebServiceAdmin(admin.ModelAdmin): prepopulated_fields = {'slug': ('name',)} -class AttributeReleaseInline(admin.TabularInline): - model = models.AttributeRelease - - def formfield_for_choice_field(self, db_field, request, **kwargs): +class AttributeReleaselineForm(forms.ModelForm): + class Meta: def choices(ctx): return [('', _('None'))] + get_attribute_names(ctx) - if db_field.name == 'attribute_name': - kwargs['choices'] = to_iter(choices)({'user': None, 'request': None}) - return super(AttributeReleaseInline, self).formfield_for_choice_field(db_field, request, **kwargs) + + model = models.AttributeRelease + widgets = { + 'attribute_name': forms.Select(choices=to_iter(choices)({'user': None, 'request': None})) + } + +class AttributeReleaseInline(admin.TabularInline): + model = models.AttributeRelease + form = AttributeReleaselineForm + class A2ClientAdmin(ClientAdmin): inlines = [AttributeReleaseInline] diff --git a/authentic2_idp_oauth2/models.py b/authentic2_idp_oauth2/models.py index cee66d4..3303076 100644 --- a/authentic2_idp_oauth2/models.py +++ b/authentic2_idp_oauth2/models.py @@ -18,8 +18,7 @@ class AttributeRelease(models.Model): client = models.ForeignKey(A2Client, verbose_name=_('client')) name = models.CharField(verbose_name=_('name'), max_length=64) attribute_name = models.CharField(max_length=64, - verbose_name=_('attribute name'), - choices=(('', _('None')),)) + verbose_name=_('attribute name')) class Meta: verbose_name = _('OAuth2 attribute release')