django-pyodbc queries returning fields with ANSI Padding Status ON, how to strip out whitespace?

StackOverflow https://stackoverflow.com/questions/20534535

문제

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?

도움이 되었습니까?

해결책

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()
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top