hi chris,
have a look:
def field_length(fname):
max = None
try: length = self.tableobj.c[fname].type.length
except: length = None
else: max = length
try: precision = self.tableobj.c[fname].type.precision
except: precision = None
else:
if max is None:
max = 0
max += (1 + precision)
return max
where fname is the name of the field
best regards,
alex
Chris Wagner wrote:
> Hi.
>
> I'm looking to reflectively determine the maximum length that is
> allowed for a given field.
>
> For example, suppose we have a model defined like so:
> class Person(Entity):
> name = Field(Unicode(128))
>
> I want to be able to find that length (128, in this case) at runtime,
> to streamline form validation. I.e., I want to be able to do
> something like this to validate forms:
> if POST['name'] > Person.name.length:
> # Display an error message and re-render form...
>
> Any help is much appreciated. Thanks!
>
> Chris W.
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---