3

So I am querying an SQL Server DB which has many CHAR fields with ANSI Padding Status ON. This means that for a CHAR(10) field, the value may be "123" but I'm instead receiving "123......." (whitespace) in the result.

Is there a best practice method to handle this?

DanH
  • 5,498
  • 4
  • 49
  • 72

1 Answers1

1

Apply python's strip before you save it.

Or add a method to the model which strips whitespace from the property when called. You could even override the default getter method.

@property
def stripped_foo(self):
    return self.foo.strip()
John Mee
  • 50,179
  • 34
  • 152
  • 186
  • 1
    This is not for saving to the DB, this is for pulling data from the DB. It outputs with the extra whitespace. I'm aware I could just use strip everywhere I make queries with this model, but that seems redundant. There should be a single place I can define the value of this field post-query. – DanH Dec 12 '13 at 04:08