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