It doesn't have to be a callable, you can just do something like: recipientUser = ShowValidContactList(currentUser=self.currentUser)
I never used that kwargs.pop function (I didn't know you could do that), but I have code like this: class ExperimentForm(ModelForm): """ Generate form to handle experiment information. """ def __init__(self, user, *args, **kwargs): super(ExperimentForm, self).__init__(*args, **kwargs) try: preferences = Preferences.objects.get(user=user) That last 'user' is just what came from the function call in the view. - Paulo 2009/8/6 Julián C. Pérez <jcp...@gmail.com> > > My real problem it that the field should looks like: > --- > recipientUser = ShowValidContactList(currentUser=_something_, > label=u'Send to') > --- > and if I have a form's init method like... > --- > def __init__(self, *args, **kwargs): > self.currentUser = kwargs.pop('currentUser', None) > super(SendMessageForm, self).__init__(*args, **kwargs) > --- > it won't change the current user already defined in the field > > Now, I want to make something like... > --- > recipientUser = ShowValidContactList(currentUser=getCurrentUser, > label=u'Send to') > --- > where 'getCurrentUser' is a callable function similar to: > --- > def get_image_path(instance, filename): > return 'photos/%s/%s' % (instance.id, filename) > > class Photo(models.Model): > image = models.ImageField(upload_to=get_image_path) > --- > how can I do that? > > On Aug 6, 9:58 am, Daniel Roseman <dan...@roseman.org.uk> wrote: > > On Aug 6, 3:34 pm, Julián C. Pérez <jcp...@gmail.com> wrote: > > > > > > > > > Hi > > > I tried doing that... > > > But it does not work > > > For example, if I do something like... > > > --- > > > class SendMessageForm(forms.Form): > > > recipientUser = ShowValidContactList(label=u'Send to') > > > messageSubject= forms.CharField(label=u'Subject') > > > messageContent = forms.CharField > > > (label=u'Content',widget=forms.Textarea()) > > > def __init__(self, currentUser): > > > self.currentUser = currentUser > > > super(SendMessageForm, self).__init__(*args, **kwargs) > > > --- > > > that init method in my custom form class won't change anything in the > > > already defined ShowValidContactList field > > > > Because you are clobbering the existing parameters to __init__. You > > should do it like this: > > > > def __init__(self, *args, **kwargs): > > self.currentUser = kwargs.pop('currentUser', None) > > super(SendMessageForm, self).__init__(*args, **kwargs) > > > > -- > > DR. > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---