Git Product home page Git Product logo

django-address's People

Contributors

arbeiterz avatar banagale avatar benbb96 avatar bendog avatar boulderdave avatar davidkircos avatar devidw avatar fellu avatar furious-luke avatar fuzzycode avatar jacinda avatar jonblum avatar jpulec avatar karbassi avatar kevinroche avatar max-nicholson avatar pyarun avatar pydanny avatar theunraveler avatar timjonez avatar xjlin0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-address's Issues

Customize options to geocomplete (like `type`)

Sometimes you don't want to allow a user to choose from any kind of location, but you want to scope it to a certain type (e.g., cities only). The JQuery Geocomplete API accepts a [type parameter](https://developers.google.com/maps/documentation/javascript/places?csw=1#place_search_requests) which gets passed though. It can be set to one of these [types](Places for autocomplete requests:
https://developers.google.com/places/supported_types#table3).

This is very simple to implement and just requires an additional option to geocomplete.

Currently I have copied addresses.js into my code and customized it, but this issue is to generalize support for this option or maybe any option to avoid such hacking.

Use autocomplete instead of selects in admin

The dropdown selects in the admin for selecting localities etc will quickly become unwieldy with many different entries. I should replace them with autocompletes or something similar to make it easier.

Documentation

It might be helpful to add the import to the documentation.

from address.models import AddressField

Also, might want to add that 'address', needs added to the settings.py's INSTALLED_APPS

django 2.0, missing 1 required positional argument: 'on_delete'

File "/home/user/.virtualenvs/rola/lib/python3.5/site-packages/address/models.py", line 171, in State
country = models.ForeignKey(Country, related_name='states')
TypeError: init() missing 1 required positional argument: 'on_delete'.
Django 2.0 requires on_delete to be explicitly set. Hence using this with django 2.0 results in the above missing positional argument.

How to get a integrate correctly in my form

Hi,
I'm kind of new in the Django community and I am looking to integrate django-address in my code. Although the address firld is visible it seems to contain no auto-complete and once an address is entered it is not saved in my database. It al works fine when I use the admin. Can you help me?
Regards,
Jackie

In my models.py I have:

from address.models import AddressField


class Member(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    address = AddressField(blank=True, null=True)

In my forms.py I have:

class MemberForm(forms.ModelForm):
    class Meta:
        model = Member
        address = AddressField
        fields = ('address', 'birth_date', 'bio', 'active', 'other_details' )

In my views.py:

def update_profile(request):
    if request.method == 'POST':
        user_form = UserForm(request.POST, instance=request.user)
        member_form = MemberForm(request.POST, instance=request.user.member)
        if user_form.is_valid():
            try:
                user_form.save()
                member_form.save()
            except:
                pass
        # else:
        #     messages.error(request, _('Please correct the error below.'))
    else:
        user_form = UserForm(instance=request.user)
        member_form = MemberForm(instance=request.user.member)
    return render(request, 'profile.html', {
        'user_form': user_form,
        'member_form': member_form,
    })

and finally my profile.html:

               <form method="post">
                  {% csrf_token %}
                  {{ user_form|crispy }}
                  {{ member_form|crispy }}
                  <button class="btn btn-default" type="submit">Save changes</button>
                </form>

Split the `dev` branch into separate repository?

Due to the development branch having a very different data schema and access methods, I've been intending on splitting the repository into something like django-address2. The reasoning behind this is to ensure anyone who is happy using the current master branch doesn't suddenly have their code break during an upgrade, and can continue to receive bug fixes for the old system.

I'm not 100% sold on this plan, and would be equally happy to continue the same repository so long as users are happy to do a little work when the development branch finally gets merged. Maybe users with an opinion on the matter could comment?

Thanks!

no completion of address

Django version: 1.8
django-address 0.1.3

after adding AddressField to my model and create migrations there is no address completion within admin menu. Entered address will be saved as raw within an new address object without any other data.

where can i find the djangoutils package?

I am getting an error importing: from djangoutils.conv import to_address

line 4 in 'address/forms.py'

I assume it is package I need to pip install but I am having trouble finding it.

perhaps its a typo?

Thanks!

PS. your library looks very useful

Cut a 0.1.6 release?

What about releasing 0.1.6 to pypi?
There are important commits like the support for multiple ZIP-codes per town.

Locality Integrity Error: django.db.utils.IntegrityError: (1062, "Duplicate entry...

Hi,
I'm using MySQL for my database and noticed trying to INSERT new Localities into the DB returns an IntegrityError when the name+postal_code composite key is duplicated. Seeing that there are multiple zip codes that can exist under a single locality ("Orlando, FL, 32801", "Orlando, FL, 32802", etc...), wouldn't it make sense to build the composite key based around name+postal_code instead? Therefore you could have multiple zips under one Locality e.g. (Orlando-32801, Orlando-32802, etc...)?

See shell output below:

from address.models import Locality
l = Locality(name="Orlando", postal_code="32801", state_id=10)
l.save()
Traceback (most recent call last):
File "", line 1, in
File "/Users/kevincook/.venv/untitled/lib/python3.4/site-packages/django/db/models/base.py", line 710, in save
force_update=force_update, update_fields=update_fields)
File "/Users/kevincook/.venv/untitled/lib/python3.4/site-packages/django/db/models/base.py", line 738, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/Users/kevincook/.venv/untitled/lib/python3.4/site-packages/django/db/models/base.py", line 822, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/Users/kevincook/.venv/untitled/lib/python3.4/site-packages/django/db/models/base.py", line 861, in _do_insert
using=using, raw=raw)
File "/Users/kevincook/.venv/untitled/lib/python3.4/site-packages/django/db/models/manager.py", line 127, in manager_method
return getattr(self.get_queryset(), name)(_args, *_kwargs)
File "/Users/kevincook/.venv/untitled/lib/python3.4/site-packages/django/db/models/query.py", line 920, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/Users/kevincook/.venv/untitled/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 974, in execute_sql
cursor.execute(sql, params)
File "/Users/kevincook/.venv/untitled/lib/python3.4/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/Users/kevincook/.venv/untitled/lib/python3.4/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/Users/kevincook/.venv/untitled/lib/python3.4/site-packages/django/db/utils.py", line 97, in exit
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Users/kevincook/.venv/untitled/lib/python3.4/site-packages/django/utils/six.py", line 658, in reraise
raise value.with_traceback(tb)
File "/Users/kevincook/.venv/untitled/lib/python3.4/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/Users/kevincook/.venv/untitled/lib/python3.4/site-packages/django/db/backends/mysql/base.py", line 124, in execute
return self.cursor.execute(query, args)
File "/Users/kevincook/.venv/untitled/lib/python3.4/site-packages/pymysql/cursors.py", line 161, in execute
result = self._query(query)
File "/Users/kevincook/.venv/untitled/lib/python3.4/site-packages/pymysql/cursors.py", line 317, in _query
conn.query(q)
File "/Users/kevincook/.venv/untitled/lib/python3.4/site-packages/pymysql/connections.py", line 835, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "/Users/kevincook/.venv/untitled/lib/python3.4/site-packages/pymysql/connections.py", line 1019, in _read_query_result
result.read()
File "/Users/kevincook/.venv/untitled/lib/python3.4/site-packages/pymysql/connections.py", line 1302, in read
first_packet = self.connection._read_packet()
File "/Users/kevincook/.venv/untitled/lib/python3.4/site-packages/pymysql/connections.py", line 981, in _read_packet
packet.check_error()
File "/Users/kevincook/.venv/untitled/lib/python3.4/site-packages/pymysql/connections.py", line 393, in check_error
err.raise_mysql_exception(self._data)
File "/Users/kevincook/.venv/untitled/lib/python3.4/site-packages/pymysql/err.py", line 120, in raise_mysql_exception
_check_mysql_exception(errinfo)
File "/Users/kevincook/.venv/untitled/lib/python3.4/site-packages/pymysql/err.py", line 112, in _check_mysql_exception
raise errorclass(errno, errorvalue)
django.db.utils.IntegrityError: (1062, "Duplicate entry 'Orlando-10' for key 'address_locality_name_294493a5b63f9602_uniq'")

unable to use two AddressField in one Model

Hi,

i created a Model like this:

class Company(models.Model):
    name = models.CharField(max_length=255)
    address = AddressField()
    billingAddress = AddressField(blank=True, null=True)

which results in the following error if i try to create the Migration Files.

python manage.py makemigrations
SystemCheckError: System check identified some issues:

ERRORS:
usermanager.Company.address: (fields.E304) Reverse accessor for 'Company.address' clashes with reverse accessor for 'Company.billingAddress'.
    HINT: Add or change a related_name argument to the definition for 'Company.address' or 'Company.billingAddress'.
usermanager.Company.billingAddress: (fields.E304) Reverse accessor for 'Company.billingAddress' clashes with reverse accessor for 'Company.address'.
    HINT: Add or change a related_name argument to the definition for 'Company.billingAddress' or 'Company.address'.

Setting attrs for AddressWidget in django admin doesn't work

from django.contrib import admin
from address.forms import AddressField, AddressWidget
from .models import Property

class PropertyAdmin(admin.ModelAdmin):
formfield_overrides = {
AddressField: {'widget': AddressWidget(attrs={"size": "150"})}
}

setting the size to 150 doesn't work.

Error when querying anything in Mexico

When querying a location in Mexico, it always fails because the state code is larger than 3 digits.

E.g., when searching for "Alberto Carrera Torres, Guadalupe, Cerritos, México" it shows the error:

Invalid state code (too long): S.L.P.

I think that it is showing states abreviation instead of the 3-digit state codes. See here:
https://en.wikipedia.org/wiki/Template:Mexico_State-Abbreviation_Codes

Can't see anywhere in the response where I can get that 3-digit state code.

How to use custom Google Geocoding API key?

My data migration failed in production (on Heroku) with:

'The given key has gone over the requests limit in the 24'
geopy.exc.GeocoderQuotaExceeded: The given key has gone over the requests limit in the 24 hour period or has submitted too many requests in too short a period of time.

Presumably because I'm not really using a key but it's based on IP which is shared in the cloud.

I got around this by writing a managment command with the same code, which was not in a single transaction so it could convert a few at a time before failing. On the 3rd try it managed to eat a few hundred and complete... but before that it was only doing about 10-20 at a time.

Bottom line, seems like we'd like to supply our own key. But I'm not 100% sure this is how it works.

Adress field doesn't respect initial data

Hi!

I get a record from a database. I think put that into an array to pre-populate a form. Most fields work fine. The AddressField data, though, doesn't display the initial text (address.raw). Print statements show address.raw spitting out the right info, but the form shows the usual default as the initial value.

            pa = PatientApplication.objects.get(uuid=uuid)
            data={
                  "patientaddress":pa.patient.patientaddress1.raw,
                  "patientphone":pa.patient.patientphone
                  }
            form(data)

Jquery lookup behind Apache?

When running Django from the dev server, the jquery works in the Django admin and does the lookup seemingly correctly. "Powered by Google" and everything. But.... when I run it from behind Apache with WSGI, I get "Google Maps API error: MissingKeyMapError" and the lookup never happens. I did collectstatic. What else could I be doing wrong?

Autocomplete broken: $this.geocomplete is not a function

When it try to render a form with the Address field, the console shows:
Uncaught TypeError: $this.geocomplete is not a function
and thus autocomplete does not work.

Also, less important but easy to fix, the Sensor parameter is no longer required:
Google Maps API warning: SensorNotRequired: https://developers.google.com/maps/documentation/javascript/error-messages

Cannot install using "python setup.py install"

Hi, I tried to install this django app and the setup script fails to do so. I cannot use it when I specify it in INSTALLED_APPS, I cannot import it. The address dir for the package is not being created and I? cannot locate anywhere the corresponding source files for models.py etc.
django_address-0.1-py27.egg and the corresponding dir is being created, but the source files are not copied in the site-packages dir,

Upgrade form input.

Currently cannot insert an address that does not normalise via Google maps. Need to be able to do that, but also keep a way of getting a list of candidates from Google to choose from.

Instance isn't saved when trying to migrating to 0.2

Hi Luke, I am finally trying to use your 0.2 branch, and have the migration mostly working, except it's not able to save. (If you remember we emailed a few months ago, and I am migrating into django-address for the first time).

Traceback (most recent call last):
  File "/Users/john/git/myapp/mysite/products/migrations/0058_auto_20160106_1433.py", line 31, in get_addresses
    new_addr = geolocate(old_addr)
  File "/Users/john/.venv/mm/lib/python2.7/site-packages/address/operations.py", line 20, in geolocate
    return to_python(location.raw, None, self.address_model, self.component_model)
  File "/Users/john/.venv/mm/lib/python2.7/site-packages/address/models.py", line 166, in to_python
    return _to_python(value, instance, address_model, component_model)
  File "/Users/john/.venv/mm/lib/python2.7/site-packages/address/models.py", line 85, in _to_python
    obj.parent = parent
  File "/Users/john/.venv/mm/lib/python2.7/site-packages/django/db/models/fields/related.py", line 668, in __set__
    (value, self.field.rel.to._meta.object_name)
ValueError: Cannot assign "<Component: Component object>": "Component" instance isn't saved in the database.

This kind of error usually suggests that we're trying to assign a reference to a foreign key for an object not yet saved. I don't think it matters but FYI this model has a custom CharField primary key.

My code, adapted from your example is:

def get_addresses(apps, schema_editor, geolocate):
    """Load addresses from your database, converting each to
    an address string that can be used in a geolocation lookup.
    """

    my_model = apps.get_model('products.Store')
    for inst in my_model.objects.all():

        if inst.city == None or inst.state == None:
            log.info("Missing city or state for: %s", inst.id)
            continue

        # Get the string of the old address.
        old_addr = u"{}, {} {}, {}".format(
                inst.city, inst.state, inst.zipcode, inst.country.alpha3)

        # Perform a lookup to convert the string into a
        # django-address Address object.
        try:
            new_addr = geolocate(old_addr)
        except:
            log.error("Problem converting store: %s", inst.id, exc_info=True)
            continue

        log.info("Successfully converted: %s", inst.id)

        # Now you can store the address in your system.
        inst.new_address = new_addr

Admin Integration Expects Global jQuery?

I've been trying to get the autocomplete to work in the django admin, but cannot. I've correctly set up my ModelAdmin as so:

from address.forms import AddressWidget
from address.models import AddressField

class SavedDeliveryLocationAdmin(admin.ModelAdmin):
  formfield_overrides = {
    AddressField: {'widget': AddressWidget()}
  }

but when I open the admin, my console tells me that $ is not a function for address.js and Cannot read property 'extend' of undefined for jquery.geocomplete.js. It would appear that these files expect jQuery to be a global, but it is not.

I'm using django 1.9.5.

Multiple zip codes in one locality

One locality can have a number of zip codes; for instance, New York City has all zip codes of the form 100xx–104xx, 11004–05, 111xx–114xx, and 116xx. Also, sometimes people add an extra four digits to the end of the zip code to indicate a more specific location. The current implementation ties zip codes to localities and doesn't allow one locality to have multiple zip codes.

Missing components?

When running Django from the dev server, when the lookup works fine, or when I run "manage.py lookupaddresses", either way, the address only gets one component, the street number. The other components are listed under 'Available components', but are not added to the 'Chosen components'. I can add them manually, but that really isn't a good solution for 10,000+ addresses. Am I doing something stupid?

Perhaps related, when I added two addresses in the same postal_code, the postal_code is listed in components twice, even though neither of them were added to the 'Chosen components'. Shouldn't the postal_code only be added to the components once?

Failure to deploy with django-pipeline: missing Bootstrap resources

Trying to deploy on Heroku is failing because of a missing font file 'fonts/glyphicons-halflings-regular.eot' that is referenced from bootstrap. Nevermind that django-address doesn't really need this file.

At first I thought the dependency was due to the autocomplete, but I actually can't find any reference to bootstrap in all of the library.

remote:     output = self.handle(*args, **options)
remote:   File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 168, in handle
remote:     collected = self.collect()
remote:   File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 120, in collect
remote:     raise processed
remote: ValueError: The file 'fonts/glyphicons-halflings-regular.eot' could not be found with <mysite.custom_storages.S3PipelineManifestStorage object at 0x7fdacaf69b50>.

MultipleObjectsReturned: get() returned more than one Address -- it returned 5!

Hi Luke,

When a user enters the location "Columbus, Ohio, USA", this exception raises during form validation. "Dayton, OH, USA" however does not cause such a problem. I've seen the number returned vary from 3 to 5.

Internal Server Error:
Traceback (most recent call last):
...
  File "/app/mysite/snakes/views.py", line 1485, in edit_store
    if form.is_valid():
  File "/app/.heroku/python/lib/python2.7/site-packages/django/forms/forms.py", line 184, in is_valid
    return self.is_bound and not self.errors
  File "/app/.heroku/python/lib/python2.7/site-packages/django/forms/forms.py", line 176, in errors
    self.full_clean()
  File "/app/.heroku/python/lib/python2.7/site-packages/django/forms/forms.py", line 392, in full_clean
    self._clean_fields()
  File "/app/.heroku/python/lib/python2.7/site-packages/django/forms/forms.py", line 407, in _clean_fields
    value = field.clean(value)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/forms/fields.py", line 162, in clean
    value = self.to_python(value)
  File "/app/.heroku/python/lib/python2.7/site-packages/address/forms.py", line 98, in to_python
    return to_python(value)
  File "/app/.heroku/python/lib/python2.7/site-packages/address/models.py", line 192, in to_python
    return _to_python(value, instance, address_model, component_model)
  File "/app/.heroku/python/lib/python2.7/site-packages/address/models.py", line 145, in _to_python
    'consistent': consistent,
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/manager.py", line 127, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/query.py", line 405, in get_or_create
    return self.get(**lookup), False
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/query.py", line 338, in get
    (self.model._meta.object_name, num)
MultipleObjectsReturned: get() returned more than one Address -- it returned 5!

I do have a bit of custom cleaning logic, which I do not think is related:

    def clean_address(self):
        address = self.cleaned_data.get('address', None)
        if not address:
            raise forms.ValidationError("Location is a required field")
        if not address.formatted:
            raise forms.ValidationError("Please choose from known list of locations that is shown while you type")

and

    def clean(self):
        cd = self.cleaned_data
        # Set the country value based on address
        address = cd.get('address')
        if address:
            from django_countries.fields import Country
            countries = address.filter_kind(kinds.KIND_COUNTRY)
            assert countries, "Found no country in address: {}".format(address)
            cd['country'] = Country(code=countries[0].short_name)

Saving unformatted addresses causes future lookup failures

After using django-address (dev branch) in production for about a year at least, I have several thousand addresses in the respective table and about 12% of them have no formatted property. These addresses seem to both be a sign of a problem, and cause future problems too.

I am aware of a couple of possible sources of these:

  • If a user does not select from the drop-down list, this will add an unformatted location.
  • When not using Google API key, I can rate limit pretty quickly and then all responses will be unformatted. I saw this locally and I think it explains locations which LOOK like they were autocompleted in production, which have no formatted field.
  • Possibly other causes.

What's worse, it seems like these "cached" addresses are often the target of future lookups which could otherwise resolve correctly (say if it was the key issue above). I proved this by doing some tests before and after clearing out related (unformatted) addresses.

For now, I have cleared out all of these addresses manually, but I wonder if there's really value in retaining them since I don't consider the form valid if the address isn't formatted. And they seem to cause future problems. I wanted to hear the author's perspective on the benefits of keeping them at all, and the idea of an option to not keep them.

Many times added the same country, State, locality if using many languages

If I add an address with web browser configured in English the plugin works fine. It adds the Country, the State or equivalent entity, the Locality and generate the correct Address.
If other user, with the web browser configured in Spanish add the same address the result is that the plugin add another Country [(1, "Spain", "ES"), (2, "España", "ES")], another State [(1, "Castilla y León", "CL", 1), (2, "Castilla y León", "CL", 2)], another locality...
This is not fine, because if i want to filter all address by Country, or other grouping entity, it will not work.

Other question. Is this project still active? If not, any recommended fork?

Thank you.

Issue with Django 1.9

I am trying out django 1.9 and getting this:

Traceback (most recent call last):
File "manage.py", line 10, in
execute_from_command_line(sys.argv)
File "lib/python2.7/site-packages/django/core/management/init.py", line 350, in execute_from_command_line
utility.execute()
File "lib/python2.7/site-packages/django/core/management/init.py", line 324, in execute
django.setup()
File "lib/python2.7/site-packages/django/init.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/init.py", line 37, in import_module
import(name)
File "/Users/mattmatijevich/Documents/next-door-now/trunk/ndn/website/models.py", line 14, in
from address.models import AddressField
File "lib/python2.7/site-packages/address/models.py", line 3, in
from django.db.models.fields.related import ForeignObject, ReverseSingleRelatedObjectDescriptor
ImportError: cannot import name ReverseSingleRelatedObjectDescriptor

Register to PyPI

Please, add this package to PyPI.
I want to make one-step install in my application via pip requirements.txt

Thanks

Improper value rendered in the template

I would like to get the value from a form field via the template such as 'San Francisco, CA, USA' like so:

{{ form.address_field.value }}

Instead I receive a number which I am assuming is the PK to a referencing table. Is this a bug or is there another way to reference this value?

Lookup sometimes doesn't parse/save zipcodes

When I have users enter an address, I'm asking for city/state/zip/country. Currently I receive these in separate fields but my plan was to only have 1 field moving forward for the address. But sometimes, the lookup appears to discard the zipcode:

This works:

s.address = "Richardson, TX 75081, USA"
<Address: Richardson, TX 75081, USA>

But this doesn't:

s.address = "Wausau, WI 54401, USA"
<Address: Wausau, WI, USA>

I've tried to speculate on why this could be, such as maybe this zipcode is not actually in Wausau (but it appears to be). However in any case, my concern is that I'd be throwing away data to only use the address field it appears. How do you recommend this be handled?

It appears that this is only a problem if the user doesn't enter a street address. I am thinking I may tell users that if the zipcode doesn't "stick" they need to provide a street address in their zipcode, and I will just not display the street part.

s.address = "2908 Christian Wausau, WI"
<Address: 2908 Christian Ave, Wausau, WI 54401, USA>

Installing the app via pip with django version 1.10 errors

If this is repeatable by someone, let me know.

Installing via pip and adding to the INSTALLED_APPS='address' works.

However, running python manage.py migrate causes an error that says something like:
"Country in not in INSTALLED_APPS"

Would like to make address optional and/or custom error message

I am concerned about users typing in an address such as "usa" (lowercase) and not selecting an autocomplete option, so I wanted to provide a more specific message than "Invalid value". At first I tried to set required=False and planned on customizing clean_address however this did not work since AddressField's to_python always raises.

To work around, I subclassed AddressField:

class CustomMessageAddressField(AddressField):
    def to_python(self, value):
        from django.core.exceptions import ValidationError
        try:
            val = super(CustomMessageAddressField, self).to_python(value)
        except ValidationError:
            raise ValidationError("Please enter a location and choose from the displayed list of options.")
        return val

I'm not sure how the required field is supposed to work but seems like to_python should only fail if this is True. Also some others might actually want to make the address field not required.

All of this might be a 1 line change, but I defer to Luke on how to best address it. No pun intended.

The other validation step I'm adding is requiring at least a city to be provided. This potentially could be another set of flags that might be generally useful.

    def clean_address(self):
        from address import kinds
        address = self.cleaned_data.get('address')
        cities = address.filter_kind(kinds.KIND_LOCALITY)
        if not cities:
            raise forms.ValidationError("Please provide at least a city and country")
        return address

KeyError: u'postal_code_suffix'

When I use two legitimate addresses, varying only by a street number, one works and one fails.

Works: s.address = "2021 Cap Rock, Richardson, TX 75080" (without zipcode also works)
Fails: s.address = "2044 Cap Rock, Richardson, TX 75080"

in ()
----> 1 s.address = "2044 Cap Rock, Richardson, TX 75080"

/Users/john/.venv/mm/lib/python2.7/site-packages/address/models.pyc in set(self, inst, value)
330
331 def set(self, inst, value):
--> 332 super(AddressDescriptor, self).set(inst, to_python(value))
333
334

/Users/john/.venv/mm/lib/python2.7/site-packages/address/models.pyc in to_python(value, instance, address_model, component_model, geolocator)
169 # if that fails then store directly.
170 elif isinstance(value, string_types):
--> 171 return lookup(value, instance, address_model, component_model, geolocator)
172
173 # A dictionary of named address components.

/Users/john/.venv/mm/lib/python2.7/site-packages/address/models.pyc in lookup(address, instance, address_model, component_model, geolocator)
201 else:
202 return address_model.objects.create(formatted=address)
--> 203 return to_python(location.raw, instance, component_model)
204
205

/Users/john/.venv/mm/lib/python2.7/site-packages/address/models.pyc in to_python(value, instance, address_model, component_model, geolocator)
176 # Attempt a conversion.
177 try:
--> 178 return _to_python(value, instance, address_model, component_model)
179 except InconsistentDictError:
180 formatted = value.get('formatted_address', None)

/Users/john/.venv/mm/lib/python2.7/site-packages/address/models.pyc in _to_python(value, instance, address_model, component_model)
54 kind_table = {}
55 for comp in components:
---> 56 kinds = [KEY_KIND_TABLE[k] for k in comp.get('types', [])]
57 kind = reduce(lambda x,y: x|y, kinds, 0)
58 short_name = comp.get('short_name', '')

KeyError: u'postal_code_suffix'

Add address merging into admin

When correcting raw addresses we will need to be able to merge multiple addresses into a single entity. I'll need to modify the admin to do this as easily as possible.

Localities are assigned the wrong zip/postal code

In an attempt to reuse Localities, the wrong zip code is assigned if the city name matches. For example:

First lookup returns result of: 123 Any Rd, Mytown, CA 90210, United States

Second lookup returns result of: 345 Some Dr, Mytown, CA, 90211 United States

When the second address is added, it attaches itself to the existing "Mytown", and that Mytown shows a zip code of 90210. The Raw and Formatted fields have 90211, but the foreign key to locality implies the wrong zip code.

Where is lookupaddresses management command?

Docs specify: "You will need to run the lookupaddresses management command".

When I run "manage.py --help" I don't see this option, nor do I see it in the source.

I am using the dev branch.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.