It uses Python's ability to define functions which can accept
arbitrary parameters.
If you define a function as
def func(*args, **kwargs):
# args and kwargs can be any identifier - it's the *s that do the trick
print args
print kwargs
...then when the function is called args will be bound to a list of
all parameters (after normal named parameters) to the function, and
kwargs will be a dictionary of the keyword parameters.
It also works from the calling side - you can 'unpack' sequences and
dictionaries into argument tuples and keyword arguments using the same
syntax:
args = [1,2,3]
kwargs = {'debug':True}
func(*args, **kwargs)
More info about variadic functions here:
http://docs.python.org/tut/node6.html#SECTION006720000000000000000
In Django's case, the get_* functions parse the keys of the dictionary
(the keyword arg names) in order to decide what the SQL expression
should be, and use the values to determine what to substitute in. It's
pretty clever, especially because it can traverse joins to refer to
attributes of related objects.
HTH
xtian
On 8/5/05, Maniac <[EMAIL PROTECTED]> wrote:
>
> Hello!
>
> First, let me express obligatory excitement about Django. It's
> fantastic! When programming with Delphi I always dreamed about some tool
> that would generate classes representing DB tables in language syntax.
> For it be possible to write just 'poll.pub_date', not
> 'poll.fieldbyname('pub_date').asdatetime'. With Django dream just came true!
>
> So here's my question. I'm a realtively new Python programmer so when I
> encounter thing like this:
>
> polls.get_object(question__startswith='What')
>
> I can't get how it exactly works? 'question__startswith' doesn't look
> like a variable existing somewhere because if would then Django should
> declare all possible combinations of all fields and filters which seems
> unlikely. So if it's some Python feature where can I read about it?
>
> Thank you in advance!
>