6

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.

Community
  • 1
  • 1
ApathyBear
  • 9,057
  • 14
  • 56
  • 90

1 Answers1

5

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:

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • How is django-address outdated? It has more commits in 2015 than django-postal, and already updated for Django 1.9. I'm not being facetious, I'm actually trying to decide how to choose so any extra comments would be appreciated. – John Lehmann Oct 19 '15 at 13:27
  • @JohnLehmann yeah, it was outdated in 2014 :) Thanks for the point! – alecxe Oct 19 '15 at 20:08