Question

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.

Was it helpful?

Solution

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:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top