django - How to change labels for permissions? -
i have form:
class newuserform(forms.modelform): first_name = forms.charfield(label=u'first name', required=true) last_name = forms.charfield(label=u'last name', required=true) permissions = forms.modelmultiplechoicefield(permission.objects.none(), widget=forms.checkboxselectmultiple) def __init__( self, *args, **kwargs ): super( newuserform, self ).__init__( *args, **kwargs ) ctypes = contenttype.objects.filter( q(app_label='articles') | q(app_label='tags') ) self.fields['permissions'].queryset = permission.objects.filter(content_type__in=ctypes) class meta: model = user and in template permissions shows me labels this:
[] articles | article | can change article [] articles | article | can delete article [] articles | article | can view article [...] how change labels? want (for example): "can change article", maybe in other language.
you can subclass modelmultiplechoicefield , define label_from_instance method.
class mymodelmultiplechoicefield(modelchoicefield): def label_from_instance(self, obj): return "%s" % obj.name # e.g. 'can change article' then use field subclass in form.
class newuserform(forms.modelform): ... permissions = mymodelmultiplechoicefield(permission.objects.none(), widget=forms.checkboxselectmultiple) ...
Comments
Post a Comment