Hi,
I am working with a Table in which one of the fields has the
unique=True attribute.

class Individual(Entity):
    name = Field(String(20), unique=True)
    favorite_color = Field(String(20), default='undefined')

I would like to make it behave so that, everytime I instantiate a new
Individual record, it checks first whether there is already a field
with the same ".name" value in the database; if it doesn't, it should
create a new record, otherwise, it should update the existing one.

examples:
>>> me = Individual('batman')
>>> me.favorite_color
'undefined'
>>> me.favorite_color = 'yellow'

>>> me_again = Individual('batman')
>>> me_again.favorite_color
'yellow'

Which is the most proper way to implement this behaviour?
Is there any parameter that I should add when I declare the name Field ?
Or, should I customize Individual.__init__? And how?


p.s. I couldn't find any example on unique fields in elixir's
documentation, so I sent you an example that I wrote for myself:
- 
http://elixir.ematia.de/trac/attachment/ticket/77/test_DuplicatedEntriesElixir.py


-- 

My blog on bioinformatics (now in English): http://bioinfoblog.it

--~--~---------~--~----~------------~-------~--~----~
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