Implemented lookups in metadata

This commit is contained in:
Roberto Rosario
2011-02-06 03:51:10 -04:00
parent b0f31f2a8f
commit 858592fc5b
4 changed files with 22 additions and 1 deletions

View File

@@ -12,6 +12,7 @@ from common.forms import DetailForm
from models import Document, DocumentType, DocumentTypeMetadataType
from documents.conf.settings import AVAILABLE_FUNCTIONS
from documents.conf.settings import AVAILABLE_MODELS
class DocumentForm(forms.ModelForm):
@@ -67,6 +68,15 @@ class MetadataForm(forms.Form):
except Exception, err:
self.fields['value'].initial = err
if self.metadata_type.lookup:
try:
choices = eval(self.metadata_type.lookup, AVAILABLE_MODELS)
self.fields['value'] = forms.ChoiceField(label=self.fields['value'].label)
self.fields['value'].choices = zip(choices, choices)
except Exception, err:
self.fields['value'].initial = err
self.fields['value'].widget=forms.TextInput(attrs={'readonly':'readonly'})
id = forms.CharField(label=_(u'id'), widget=forms.HiddenInput)
name = forms.CharField(label=_(u'Name'),
required=False, widget=forms.TextInput(attrs={'readonly':'readonly'}))