[Grok-dev] Grok tutorial - last example, deleting and editing
steveschmechel at yahoo.com
Thu Jul 9 14:56:16 EDT 2009
You are on the right track.
That particular example is very general so the particulars of how you would delete the items are still very open to design.
For example, you could create links or buttons in the list that take you to a view that deletes the object, or you could move to an edit form for a particular item and delete it from there.
If you want to stick to just the existing form in the example, you could create a text box on the existing form where you type in the name of the item you want to delete and post back to the same form. The update method would then have to determine that you want to delete rather than add a new object by examining the content of the form fields.
All the url/form/view details will determine how you inform your method which item to delete from the collection.
To actually remove the item from the collection and from persistent storage, you call the Python "del" built-in function on the object in the container. To get the particular object you must provide the same key used in the example when adding (the "name"):
Note: If you delete an item from a view that is using that item as it's context, make sure you redirect direct to another content object before you delete it, or you will get an error.
For example, if you create an edit form for individual items, you can include a delete button on that form.
def delete(self, **data):
This will delete the object you were editing and return you to the parent object.
For more information on forms, see:
Hope this helps.
--- On Thu, 7/9/09, agatw <veela at wp.pl> wrote:
> From: agatw <veela at wp.pl>
> Subject: [Grok-dev] Grok tutorial - last example, deleting and editing
> To: grok-dev at zope.org
> Date: Thursday, July 9, 2009, 6:29 AM
> I am new around here, I just started using Python and Grok.
> I followed the Grok tutorial and I have a question.
> How can I delete and edit an entry from the last example in
> tutorial (this
> one with containers)?
> I tried to make a new function, def Delete, but it didn't
> work. I suppose I
> just know Python too little.
> I'd be grateful if someone helped. Really thank you.
> Best regards,
> View this message in context: http://www.nabble.com/Grok-tutorial---last-example%2C-deleting-and-editing-tp24408495p24408495.html
> Sent from the Grok mailing list archive at Nabble.com.
> Grok-dev mailing list
> Grok-dev at zope.org
More information about the Grok-dev