may be BUG. SyntaxError: non-keyword arg after keyword arg

103 views
Skip to first unread message

sector119

unread,
May 28, 2008, 5:32:56 AM5/28/08
to Django users
Hi All!

My Transaction model have method:

def _get_serial(self):
return
Transaction.objects.filter(commit_date=datetime.date.today(),
operator__office=self. operator.office).count() + 1

CAUSE ERROR

File "/home/sector119/devel/eps_src/eps/apps/transactions/
models.py", line 30
return
Transaction.objects.filter(commit_date=datetime.date.today(),
operator__).count() + 1
SyntaxError: non-keyword arg after keyword arg

"operator__office=self.operator.office" WAS truncated to the
"operator__" in traceback...

WORKS GOOD

def _get_serial(self):
return
Transaction.objects.filter(commit_date=datetime.date.today()).filter(operator__office=self.
operator.office).count() + 1


Is it a bug, or I misunderstood something in filter usage?

Thanks!

Peter Rowell

unread,
May 28, 2008, 3:31:27 PM5/28/08
to Django users
> SyntaxError: non-keyword arg after keyword arg
>
> "operator__office=self.operator.office" WAS truncated to the
> "operator__" in traceback...

The ORM filter() method uses double underscore "__" in a magic way.
See http://www.djangoproject.com/documentation/db-api/#filtering-objects

James Bennett

unread,
May 28, 2008, 4:42:34 PM5/28/08
to django...@googlegroups.com
On Wed, May 28, 2008 at 4:32 AM, sector119 <sect...@gmail.com> wrote:
> Is it a bug, or I misunderstood something in filter usage?

It looks like you have stray whitespace or line breaks in the middle
of things which should be continuous text. This would, naturally, lead
to strange behavior. For example, this works:

User.objects.get(username__exact='bob')

But this probably won't:

User.objects.get(user name
__ exact='bob')

Double-check your code.

--
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

Reply all
Reply to author
Forward
0 new messages