[Grok-dev] Attribute error from Grok Development Book Chapter 5 source code.

Jan-Wijbrand Kolman janwijbrand at gmail.com
Mon Jan 10 04:07:56 EST 2011

On 1/8/11 23:03 PM, Michael Thamm wrote:
> Hi,
> I am working through the chapter 5 source code from the Grok development
> book and I get an Attribute error.
> id = str(self.next_id)
> AttributeError: 'Project' object has no attribute 'next_id'
> Which seems to be caused by this line:
> form_fields = grok.AutoFields(Project).omit('next_id')
> Because the field is omitted from the form.
> It is in the interface definition.
> How can I omit a field from the form and still see it in the methods?
> The code I am using is unaltered from the book.
> This is the add project code:

Ok, I see the confusion. Let me try to exlain:

Because the "next_id" field is omitted from the form fields, the 
applyData() call in the form action handling code, will not set a 
"next_id" attribute on the newly created Project instance. Hence, the 
methods of the Project instance cannot find the attribute (as it is 
indeed not there).

What we usually do is to either make sure the necessary attributes of an 
object are set in the __init__(), or define class-level defaults for 
these attributes.


regards, jw

More information about the Grok-dev mailing list