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

Michael Thamm webmaster at morningcat.com
Sat Jan 8 17:03:19 EST 2011


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:

class AddProjectForm(grok.AddForm):
    grok.context(Todo)
    grok.name('index')
    form_fields = grok.AutoFields(Project).omit('next_id')

    label = "To begin, add a new project"
    template = grok.PageTemplateFile('custom_edit_form.pt')

    @grok.action('Add project')
    def add(self,**data):
        project = Project()
        self.applyData(project,**data)
        id = str(self.context.next_id)
        self.context.next_id = self.context.next_id+1
        self.context[id] = project
        return self.redirect(self.url(self.context[id]))

Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/grok-dev/attachments/20110108/c3367069/attachment.html 


More information about the Grok-dev mailing list