I see what you're saying. Maybe you're looking for something more like this?

def method1(self, param1=sensible_default, param2=sensible_default,
param3=sensible_default):
    print param1, param2, param3

The variable names must be specified in the method arguments like above if
you wish to reference them by name inside the method itself. With this
method, you will also need to call it with: model.method1(**params)

On Tue, Apr 16, 2013 at 9:59 PM, jayhalleaux <jay.halle...@gmail.com> wrote:

> but if I did that then i would have a variable named kwargs.
>
> and it would be print kwargs['param1'], etc
>
> Why even unpack the dictionary?  I could just pass the dictionary instead.
>
>
> On Tuesday, April 16, 2013 11:08:42 PM UTC-4, Brad Pitcher wrote:
>
>> It should be:
>> model.method1(**params)
>> On Apr 16, 2013 7:49 PM, "jayhalleaux" <jay.ha...@gmail.com> wrote:
>>
>>>  Not really a Django question but I'm trying to create a model method
>>> that does not have a fixed set of parameters.
>>>
>>> models.py
>>> Class Model_A(model.Model):
>>> ...
>>>
>>> def method1(self, **kwargs):
>>>
>>> print param1, param2, param3
>>>
>>>
>>>
>>> views.py
>>> params = dict(
>>>
>>> param1=something1,
>>> param2=something2,
>>>  param3=something3,
>>> ...
>>>
>>> )
>>>
>>> model.method1(params)
>>>
>>> In this example when I try to do something like this it states that I
>>> should have passed only 1 parameter instead of 2.
>>>
>>> I thought the whole point of using '**' to unpack dictionaries is so you
>>> don't have to have a fixed number of parameters.
>>>
>>> Is there something I am missing or am I doing this incorrect? First time
>>> I'm trying to create a method like this.  Normally I explicitly state all
>>> parameters.
>>>
>>> Any help is appreciated.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users...@**googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>>
>>> Visit this group at 
>>> http://groups.google.com/**group/django-users?hl=en<http://groups.google.com/group/django-users?hl=en>
>>> .
>>> For more options, visit 
>>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
>>> .
>>>
>>>
>>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to