Michael Hipp wrote:

> Actually there are about 4 columns that I would preserve. They
> must remain because the row must still be there for the user to
> fill in. It's one of those things where you create a certain
> number of (almost) empty records and then the clerk fills them
> in. Deleting is not allowed as they represent a certain "place in
> line" to the thing in the record.

Ah, okay, I understand.  Knowing what you are trying to accomplish
definitely helps clear things up.

> And iterating thru all the umpteen other rows is the very thing
> I'm trying to avoid. Some of them won't readily hold None
> (e.g. Booleans).

Sure...

> So I'm looking for a simple way to set a record back to it's
> default/empty state. (Excepting a few fields.) Is there no easy
> way to do this?

Well, if it were me, I'd just create a method called "reset" on the
entity itself that either loops through the columns (which I really
don't consider "hard" or complex), or just manually references the
columns, and resets their values to some default state:

     class MyThing(Entity):
         a = Field(String)
         b = Field(Boolean)
         c = Field(DateTime)
         d = Field(Binary)

         def reset(self):
             non_resettable_cols = ('id', 'c')
             for column in self.table.c:
                 if column.name in non_resettable_cols:
                     continue
                 setattr(self, column.name, None)

The only other alternative that I could think of would be to keep
a dictionary around that contains "default" values, and then pass
those to the `.set` method:

     defaults = {'a': None, 'b': False, 'c': None, 'd': None}

     class MyThing(Entity):
         a = Field(String)
         b = Field(Boolean)
         c = Field(DateTime)
         d = Field(Binary)

         def reset(self):
             self.set(**defaults)

Best of luck.

--
Jonathan LaCour
http://cleverdevil.org

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"SQLElixir" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to