Edgewall Software

Changes between Version 2 and Version 3 of TracDev/DataModels


Ignore:
Timestamp:
Oct 28, 2005, 4:32:51 AM (19 years ago)
Author:
Felix Collins
Comment:

Added an example for using the ticket model

Legend:

Unmodified
Added
Removed
Modified
  • TracDev/DataModels

    v2 v3  
    1313}}}
    1414
     15The fields on a model object can be edited by treating the object as a dictionary.  If you change any of the fields you must call save_changes() to have them persisted.
     16
     17To edit a ticket...
     18{{{
     19#!python
     20  import trac.env
     21  import trac.ticket.model
     22
     23  # Open Trac environment
     24  t = trac.env.Environment("path/to/trac/env")
     25 
     26  # Get the ticket you are after (how can we query for tickets?)
     27  myticket = trac.ticket.model.Ticket(t, tkt_id=1)
     28
     29  # Read a ticket field
     30  print "Changing description for ticket called %s" %myticket["summary"]
     31
     32  #Write a ticket field
     33  myticket["description"] = "My ticket now has a new description."
     34
     35  #Save your changes
     36  myticket.save_changes("myusername","Just changed the description")
     37}}}
     38 
    1539For usage examples, see [source:/trunk/trac/ticket/web_ui.py trac.ticket.web_ui].
    1640