문제

I am building some models, and I need to collect an address. Thing is, I want the address to be be collected in one model field, yet the fields for the address could span over multiple lines.

For example:

street:

city:

zip:

state:

Mine don't look like these, but you get the idea. The data needs to be stored in one model field.

도움이 되었습니까?

해결책

TextField is a perfect choice here:

class TextField([**options])

A large text field. The default form widget for this field is a Textarea.

Since textarea is used as a widget, it "handles" newlines for you.


I would recommend rethink the idea of storing the address inside the model field. Instead, consider having a special model(s) handling the address, since, in the future, you would probably want to query the data by city, country, street, zip etc. It would more clean, transparent and easy to filter.

See also:

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top