Giter VIP home page Giter VIP logo

django-countries's Introduction

Django Countries

PyPI version

Build status

A Django application that provides country choices for use with forms, flag icons static files, and a country field for models.

Country names are translated using Django's standard gettext. If you would like to help by adding a translation, please visit https://www.transifex.com/smileychris/django-countries/

Installation

  1. pip install django-countries

    For more accurate sorting of translated country names, install it with the optional pyuca package:

    pip install django-countries[pyuca]

  2. Add django_countries to INSTALLED_APPS

CountryField

A country field for Django models that provides all ISO 3166-1 countries as choices.

CountryField is based on Django's CharField, providing choices corresponding to the official ISO 3166-1 list of countries (with a default max_length of 2).

Consider the following model using a CountryField:

from django.db import models
from django_countries.fields import CountryField

class Person(models.Model):
    name = models.CharField(max_length=100)
    country = CountryField()

Any Person instance will have a country attribute that you can use to get details of the person's country:

>>> person = Person(name="Chris", country="NZ")
>>> person.country
Country(code='NZ')
>>> person.country.name
'New Zealand'
>>> person.country.flag
'/static/flags/nz.gif'

This object (person.country in the example) is a Country instance, which is described below.

Use blank_label to set the label for the initial blank choice shown in forms:

country = CountryField(blank_label="(select country)")

You can filter using the full English country names in addition to country codes, even though only the country codes are stored in the database by using the queryset lookups contains, startswith, endswith, regex, or their case insensitive versions. Use __name or __iname for the exact/iexact equivalent:

>>> Person.objects.filter(country__name="New Zealand").count()
1
>>> Person.objects.filter(country__icontains="zealand").count()
1

Multi-choice

This field can also allow multiple selections of countries (saved as a comma separated string). The field will always output a list of countries in this mode. For example:

class Incident(models.Model):
    title = models.CharField(max_length=100)
    countries = CountryField(multiple=True)

>>> for country in Incident.objects.get(title="Pavlova dispute").countries:
...     print(country.name)
Australia
New Zealand

By default, countries are stored sorted for data consistency, and any duplicates are removed. These behaviours can be overridden by using the field arguments multiple_sort=False and multiple_unique=False respectively.

The Country object

An object used to represent a country, instantiated with a two character country code, three character code, or numeric code.

It can be compared to other objects as if it was a string containing the country code and when evaluated as text, returns the country code.

name

Contains the full country name.

flag

Contains a URL to the flag. If you page could have lots of different flags then consider using flag_css instead to avoid excessive HTTP requests.

flag_css

Output the css classes needed to display an HTML element as the correct flag from within a single sprite image that contains all flags. For example:

<link rel="stylesheet" href="{% static 'flags/sprite.css' %}">
<i class="{{ country.flag_css }}"></i>

For multiple flag resolutions, use sprite-hq.css instead and add the flag2x, flag3x, or flag4x class. For example:

<link rel="stylesheet" href="{% static 'flags/sprite-hq.css' %}">
Normal: <i class="{{ country.flag_css }}"></i>
Bigger: <i class="flag2x {{ country.flag_css }}"></i>

You might also want to consider using aria-label for better accessibility:

<i class="{{ country.flag_css }}"
    aria-label="{% blocktrans with country_code=country.code %}
        {{ country_code }} flag
    {% endblocktrans %}"></i>
unicode_flag

A unicode glyph for the flag for this country. Currently well-supported in iOS and OS X. See https://en.wikipedia.org/wiki/Regional_Indicator_Symbol for details.

code

The two letter country code for this country.

alpha3

The three letter country code for this country.

numeric

The numeric country code for this country (as an integer).

numeric_padded

The numeric country code as a three character 0-padded string.

ioc_code

The three letter International Olympic Committee country code.

CountrySelectWidget

A widget is included that can show the flag image after the select box (updated with JavaScript when the selection changes).

When you create your form, you can use this custom widget like normal:

from django_countries.widgets import CountrySelectWidget

class PersonForm(forms.ModelForm):
    class Meta:
        model = models.Person
        fields = ("name", "country")
        widgets = {"country": CountrySelectWidget()}

Pass a layout text argument to the widget to change the positioning of the flag and widget. The default layout is:

'{widget}<img class="country-select-flag" id="{flag_id}" style="margin: 6px 4px 0" src="{country.flag}">'

Custom forms

If you want to use the countries in a custom form, use the model field's custom form field to ensure the translatable strings for the country choices are left lazy until the widget renders:

from django_countries.fields import CountryField

class CustomForm(forms.Form):
    country = CountryField().formfield()

Use CountryField(blank=True) for non-required form fields, and CountryField(blank_label="(Select country)") to use a custom label for the initial blank option.

You can also use the CountrySelectWidget as the widget for this field if you want the flag image after the select box.

Get the countries from Python

Use the django_countries.countries object instance as an iterator of ISO 3166-1 country codes and names (sorted by name).

For example:

>>> from django_countries import countries
>>> dict(countries)["NZ"]
'New Zealand'

>>> for code, name in list(countries)[:3]:
...     print(f"{name} ({code})")
...
Afghanistan (AF)
Åland Islands (AX)
Albania (AL)

Template Tags

If you have your country code stored in a different place than a CountryField you can use the template tag to get a Country object and have access to all of its properties:

{% load countries %}
{% get_country 'BR' as country %}
{{ country.name }}

If you need a list of countries, there's also a simple tag for that:

{% load countries %}
{% get_countries as countries %}
<select>
{% for country in countries %}
    <option value="{{ country.code }}">{{ country.name }}</option>
{% endfor %}
</select>

Customization

Customize the country list

Country names are taken from the official ISO 3166-1 list, with some country names being replaced with their more common usage (such as "Bolivia" instead of "Bolivia, Plurinational State of").

To retain the official ISO 3166-1 naming for all fields, set the COUNTRIES_COMMON_NAMES setting to False.

If your project requires the use of alternative names, the inclusion or exclusion of specific countries then set the COUNTRIES_OVERRIDE setting to a dictionary of names which override the defaults. The values can also use a more complex dictionary format.

Note that you will need to handle translation of customised country names.

Setting a country's name to None will exclude it from the country list. For example:

from django.utils.translation import gettext_lazy as _

COUNTRIES_OVERRIDE = {
    "NZ": _("Middle Earth"),
    "AU": None,
    "US": {
        "names": [
            _("United States of America"),
            _("America"),
        ],
    },
}

If you have a specific list of countries that should be used, use COUNTRIES_ONLY:

COUNTRIES_ONLY = ["NZ", "AU"]

or to specify your own country names, use a dictionary or two-tuple list (string items will use the standard country name):

COUNTRIES_ONLY = [
    "US",
    "GB",
    ("NZ", _("Middle Earth")),
    ("AU", _("Desert")),
]

Show certain countries first

Provide a list of country codes as the COUNTRIES_FIRST setting and they will be shown first in the countries list (in the order specified) before all the alphanumerically sorted countries.

If you want to sort these initial countries too, set the COUNTRIES_FIRST_SORT setting to True.

By default, these initial countries are not repeated again in the alphanumerically sorted list. If you would like them to be repeated, set the COUNTRIES_FIRST_REPEAT setting to True.

Finally, you can optionally separate these "first" countries with an empty choice by providing the choice label as the COUNTRIES_FIRST_BREAK setting.

Customize the flag URL

The COUNTRIES_FLAG_URL setting can be used to set the url for the flag image assets. It defaults to:

COUNTRIES_FLAG_URL = "flags/{code}.gif"

The URL can be relative to the STATIC_URL setting, or an absolute URL.

The location is parsed using Python's string formatting and is passed the following arguments:

  • code
  • code_upper

For example: COUNTRIES_FLAG_URL = "flags/16x10/{code_upper}.png"

No checking is done to ensure that a static flag actually exists.

Alternatively, you can specify a different URL on a specific CountryField:

class Person(models.Model):
    name = models.CharField(max_length=100)
    country = CountryField(
        countries_flag_url="//flags.example.com/{code}.png")

Single field customization

To customize an individual field, rather than rely on project level settings, create a Countries subclass which overrides settings.

To override a setting, give the class an attribute matching the lowercased setting without the COUNTRIES_ prefix.

Then just reference this class in a field. For example, this CountryField uses a custom country list that only includes the G8 countries:

from django_countries import Countries

class G8Countries(Countries):
    only = [
        "CA", "FR", "DE", "IT", "JP", "RU", "GB",
        ("EU", _("European Union"))
    ]

class Vote(models.Model):
    country = CountryField(countries=G8Countries)
    approve = models.BooleanField()

Complex dictionary format

For COUNTRIES_ONLY and COUNTRIES_OVERRIDE, you can also provide a dictionary rather than just a translatable string for the country name.

The options within the dictionary are:

name or names (required)

Either a single translatable name for this country or a list of multiple translatable names. If using multiple names, the first name takes preference when using COUNTRIES_FIRST or the Country.name.

alpha3 (optional)

An ISO 3166-1 three character code (or an empty string to nullify an existing code for this country.

numeric (optional)

An ISO 3166-1 numeric country code (or None to nullify an existing code for this country. The numeric codes 900 to 999 are left available by the standard for user-assignment.

ioc_code (optional)

The country's International Olympic Committee code (or an empty string to nullify an existing code).

Country object external plugins

Other Python packages can add attributes to the Country object by using entry points in their setup script.

For example, you could create a django_countries_phone package which had a with the following entry point in the setup.py file. The entry point name (phone) will be the new attribute name on the Country object. The attribute value will be the return value of the get_phone function (called with the Country instance as the sole argument).

setup(
    ...
    entry_points={
        "django_countries.Country": "phone = django_countries_phone.get_phone"
    },
    ...
)

Django Rest Framework

Django Countries ships with a CountryFieldMixin to make the CountryField model field compatible with DRF serializers. Use the following mixin with your model serializer:

from django_countries.serializers import CountryFieldMixin

class CountrySerializer(CountryFieldMixin, serializers.ModelSerializer):

    class Meta:
        model = models.Person
        fields = ("name", "email", "country")

This mixin handles both standard and multi-choice country fields.

Django Rest Framework field

For lower level use (or when not dealing with model fields), you can use the included CountryField serializer field. For example:

from django_countries.serializer_fields import CountryField

class CountrySerializer(serializers.Serializer):
    country = CountryField()

You can optionally instantiate the field with the countries argument to specify a custom Countries instance.

REST output format

By default, the field will output just the country code. To output the full country name instead, instantiate the field with name_only=True.

If you would rather have more verbose output, instantiate the field with country_dict=True, which will result in the field having the following output structure:

{"code": "NZ", "name": "New Zealand"}

Either the code or this dict output structure are acceptable as input irregardless of the country_dict argument's value.

OPTIONS request

When you request OPTIONS against a resource (using the DRF metadata support) the countries will be returned in the response as choices:

OPTIONS /api/address/ HTTP/1.1

HTTP/1.1 200 OK
Content-Type: application/json
Allow: GET, POST, HEAD, OPTIONS

{
"actions": {
  "POST": {
    "country": {
    "type": "choice",
    "label": "Country",
    "choices": [
      {
        "display_name": "Australia",
        "value": "AU"
      },
      [...]
      {
        "display_name": "United Kingdom",
        "value": "GB"
      }
    ]
  }
}

GraphQL

A Country graphene object type is included that can be used when generating your schema.

import graphene
from graphene_django.types import DjangoObjectType
from django_countries.graphql.types import Country

class Person(ObjectType):
    country = graphene.Field(Country)

    class Meta:
        model = models.Person
        fields = ["name", "country"]

The object type has the following fields available:

  • name for the full country name
  • code for the ISO 3166-1 two character country code
  • alpha3 for the ISO 3166-1 three character country code
  • numeric for the ISO 3166-1 numeric country code
  • iocCode for the International Olympic Committee country code

django-countries's People

Contributors

adamchainz avatar adamsol avatar bounder avatar drmeers avatar fk-currenxie avatar foutrelis avatar housain-maina avatar hugorodgerbrown avatar inirudebwoy avatar interdist avatar jedie avatar jonashaag avatar ksysctl avatar matthiask avatar michael-k avatar mng-dev-ai avatar mo-mughrabi avatar omarithawi avatar pablocastellano avatar philgyford avatar pzrq avatar qcoumes avatar richardarpanet avatar rubindersinghsandhu avatar schinckel avatar simonpanay avatar smileychris avatar technickai avatar toofishes avatar vinnyrose 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  avatar

django-countries's Issues

Schema rules needed for django-south

#!python

 ! Cannot freeze field 'app.country'

 ! South cannot introspect some fields; this is probably because they are custom
 ! fields. If they worked in 0.6 or below, this is because we have removed the
 ! models parser (it often broke things).
 ! To fix this, read http://south.aeracode.org/wiki/MyFieldsDontWork

Having the schema rules in place would be nice when working with soutch.


'name' attribute not searchable from admin (lazy translation?)

When enabling search in the Django admin for a model with a CountryField, it seems that the resulting query cannot search correctly.

# models.py
class MyModel(models.Model):
    origin = CountryField(blank=True)
    author = models.CharField(max_length=50)

# admin.py
class ExploitKitAdmin(AddSubmitterModelAdmin):
    search_fields = ('origin__name', 'author')

Trying to search the respective field from the admin raises exception:

FieldError at /admin/threatfacts/malwarefamily/
Join on field 'origin' not permitted. Did you misspell 'name' for the lookup type?

I don't know the cause of the issue for certain. If I'm guessing I think it may be that the field does not return data but a lazy translation:

x = MyModel.objects.get(pk=1)
x.origin
Country(code=u'RU', flag_url='flags/{code}.gif')

x.origin.code
u'RU'

x.origin.name
<django.utils.functional.__proxy__ at 0x106614b90>

unicode(x.origin.name)
u'Russian Federation'

I think this is rooted in not being able to filter() on the field:

x = MyModel.objects.filter(origin__name="Russian Federation")
FieldError: Join on field 'origin' not permitted. Did you misspell 'name' for the lookup type?

Is this a known issue with a workaround/specific configuration needed? Am I just missing a clue on how to do model searches correctly? Or is this way off base?

Countries on Form ?

How to create a form with countries ?

country = forms.ModelChoiceField( queryset = ?)

or

country = CountryField ?

Best way to include only select countries?

I'd like to restrict the list of countries for a model to maybe 10 or so. Is there a more elegant way than to set the vast majority to None in my override in settings.py?

new translations from transifex..

Would it be possible to pull a new list of translations from Transifex? I've just finished translating the dutch countries for instance and i see quite a few other languages also got new translations.

Use pycountries for data?

There is http://pypi.python.org/pypi/pycountry which provides convenient access to several ISO country databases. Would a pull-request which changes the data backend to use this package be accepted?

My motivation is that the Debian package of django-countries, which is already patched to use the system ISO database files, would then be closer to upstream again. pycountries in Debian already uses the system ISO XML files.

Kosovo in List

Can you add Kosovo to the list?
They are recognized by the US as a country:

http://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/CountriesRecognizingKosovo.svg/1000px-CountriesRecognizingKosovo.svg.png

Or what would be the best way for doing it myself?
Just editing the static list seems no the right way to do it, since it breaks future updates.

Thanks!


Description for Taiwan

The issue for the name of Taiwan stated in issue #16 still exists.
As discussed there, most Taiwanese don't like it (being called a province of China) and consider it very offensive, despite the fact we can't change nor choose our history which led us to the difficult situation. In addition, stating Taiwan as part of China is also considered political biased. Therefore it is more neutral to state Taiwan simply as "Taiwan".
Please kindly change it, as this library is used widely in many products, and hence it would be very nice if the users are satisfied when they are choosing their nationality in the form :)

Ordering of the country list wrong if locale is not english

If I switch into French, the list of countries do appear in French, but the order is somewhat wrong. As if, it took the original English ordering of the names, and just translated it. Hence United States in French is Etats-Unis, but since United States is within the last countries in English language, Etats-Unis will appear within the last one when in French, whereas it should be in French. Any ideas how to change that behaviour?


Missing source file or documentation piece

Hello,
I've decided to use django-countries, added it to my django project, but after adding dango_countries to the INSTALLED_APPS, my application breaks with an error "Can't import module settings".

File fields.py starts with the following import:
from django_countries import settings

but there's no settings.py within the django_countries source code.


django-countries is broken on 1.7b1, with fix

Hi,

In Django 1.7, it became illegal to use ugettext at module import time as the app registry is not ready yet. Django Countries uses ugettext_lazy, so you'd think it would be OK here. However, at line 30 in django_countries/init.py:

                if name:
                    self._countries.append((code, name))

name in this context is a lazy translated string. By testing it for truthiness, it has to be translated. Therefore the module fails to import with "RuntimeError: App registry isn't ready yet"

I'm not sure exactly what use case the condition was put in to support, but either of these changes fixes the issue.

1: removing the condition

                self._countries.append((code, name))

2: Using an identity comparison

                if name is not None:
                    self._countries.append((code, name))

Cheers,

Bernie :o)

Django 1.7RC2 regression for ModelForm with django-countries field

I'm using Django 1.7RC2. I have a django-countries Country field in a model. When I try to create to a ModelForm of this model, the following error is thrown:

TypeError: Error when calling the metaclass bases
    'Countries' object does not support indexing

How to reproduce:

  1. Install Django 1.7RC2.
  2. Create a model with a Country() field.
  3. Create a ModelForm that references to this model.
  4. Initialize the form.

Can't save CountryField with None value

I have a model with a CountryField that has allowed null values. However, when creating a new instance of that model, an empty string is saved into database instead, causing unique constraints to fail. It seems that problem is in get_prep_value method, because it receives a Country object with code attribute set to None instead of primitive None value.

Example model:

class Failing(models.Model):
    country = CountryField(null=True, unique=True)
    count = models.PositiveIntegerField(default=0)

Failing code:

a, created1 = Failing.objects.get_or_create(country=None)
b, created2 = Failing.objects.get_or_create(country=None)

assert a == b
assert created1 is True
assert created2 is False

Running the tests

Hi, could you please give me a clue on how you run tests? I was first trying to run the tests only from the source with no luck (just by nosetests). Then I created a django project and added "django_countries" to installed apps and ran manage.py test, but no tests were found and run.
I'm using Django 1.4.
Thanks!


Adding list of languages

Hi,
I think it would be great if this app also have a languages list (and LanguageField). It's highly related to countries and very often when you need list of countries, you would also need languages list. Moreover, for time being, django don't have good app with translated list of languages (at least I could not find one). Easy to parse registry of languages can be found at iana.org.

Capitalization and diacritics in some country names

While comparing the names of countries in the lists with those from iso-codes (http://packages.debian.org/iso-codes) I found some minor differences that should be fixed.

The attached patch fixes all differences that I could find and for the record, those were my references:


Tests fail

I have added the django-countries app to my project and am attempting to run the tests, but they fail when executing the syncdb command from the utils/tests.py file because the tables it's trying to create are already present. My project uses django-south to handle db migrations. Here is a stack dump of one of the test failures.

#!python

======================================================================
ERROR: test_unicode (django_countries.tests.TestCountryField)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/vagrant/sg/simplegeo.com/lib/python2.6/site-packages/django_countries-1.0.5-py2.6.egg/django_countries/utils/tests.py", line 22, in setUp
    call_command('syncdb', verbosity=0, interactive=False)
  File "/home/vagrant/sg/simplegeo.com/lib/python2.6/site-packages/Django-1.2.4-py2.6.egg/django/core/management/__init__.py", line 166, in call_command
    return klass.execute(*args, **defaults)
  File "/home/vagrant/sg/simplegeo.com/lib/python2.6/site-packages/Django-1.2.4-py2.6.egg/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/home/vagrant/sg/simplegeo.com/lib/python2.6/site-packages/Django-1.2.4-py2.6.egg/django/core/management/base.py", line 351, in handle
    return self.handle_noargs(**options)
  File "/home/vagrant/sg/simplegeo.com/lib/python2.6/site-packages/South-0.7.3-py2.6.egg/south/management/commands/syncdb.py", line 99, in handle_noargs
    management.call_command('migrate', **options)
  File "/home/vagrant/sg/simplegeo.com/lib/python2.6/site-packages/Django-1.2.4-py2.6.egg/django/core/management/__init__.py", line 166, in call_command
    return klass.execute(*args, **defaults)
  File "/home/vagrant/sg/simplegeo.com/lib/python2.6/site-packages/Django-1.2.4-py2.6.egg/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/home/vagrant/sg/simplegeo.com/lib/python2.6/site-packages/South-0.7.3-py2.6.egg/south/management/commands/migrate.py", line 105, in handle
    ignore_ghosts = ignore_ghosts,
  File "/home/vagrant/sg/simplegeo.com/lib/python2.6/site-packages/South-0.7.3-py2.6.egg/south/migration/__init__.py", line 191, in migrate_app
    success = migrator.migrate_many(target, workplan, database)
  File "/home/vagrant/sg/simplegeo.com/lib/python2.6/site-packages/South-0.7.3-py2.6.egg/south/migration/migrators.py", line 221, in migrate_many
    result = migrator.__class__.migrate_many(migrator, target, migrations, database)
  File "/home/vagrant/sg/simplegeo.com/lib/python2.6/site-packages/South-0.7.3-py2.6.egg/south/migration/migrators.py", line 292, in migrate_many
    result = self.migrate(migration, database)
  File "/home/vagrant/sg/simplegeo.com/lib/python2.6/site-packages/South-0.7.3-py2.6.egg/south/migration/migrators.py", line 125, in migrate
    result = self.run(migration)
  File "/home/vagrant/sg/simplegeo.com/lib/python2.6/site-packages/South-0.7.3-py2.6.egg/south/migration/migrators.py", line 99, in run
    return self.run_migration(migration)
  File "/home/vagrant/sg/simplegeo.com/lib/python2.6/site-packages/South-0.7.3-py2.6.egg/south/migration/migrators.py", line 81, in run_migration
    migration_function()
  File "/home/vagrant/sg/simplegeo.com/lib/python2.6/site-packages/South-0.7.3-py2.6.egg/south/migration/migrators.py", line 57, in <lambda>
    return (lambda: direction(orm))
  File "/home/vagrant/sg/simplegeo.com/balboa/apps/website/migrations/0001_initial.py", line 17, in forwards
    ('public', self.gf('django.db.models.fields.BooleanField')(default=False)),
  File "/home/vagrant/sg/simplegeo.com/lib/python2.6/site-packages/South-0.7.3-py2.6.egg/south/db/generic.py", line 226, in create_table
    ', '.join([col for col in columns if col]),
  File "/home/vagrant/sg/simplegeo.com/lib/python2.6/site-packages/South-0.7.3-py2.6.egg/south/db/generic.py", line 150, in execute
    cursor.execute(sql, params)
  File "/home/vagrant/sg/simplegeo.com/lib/python2.6/site-packages/Django-1.2.4-py2.6.egg/django/db/backends/mysql/base.py", line 86, in execute
    return self.cursor.execute(query, args)
  File "/home/vagrant/sg/simplegeo.com/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-linux-i686.egg/MySQLdb/cursors.py", line 174, in execute
    self.errorhandler(self, exc, value)
  File "/home/vagrant/sg/simplegeo.com/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-linux-i686.egg/MySQLdb/connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
OperationalError: (1050, "Table 'website_license' already exists")

Cannot import with django 1.3a1

I am importing CountryField as specified in the README in my models file. When running the test server, Django does not have a problem. Similarly, running a shell through manage.py, executing the import is no problem. However, when running through apache+mod_wsgi a "cannot import name CountryField" exception is thrown. Is this an issue with django-countries or with django? I have not tested this on django 1.2 so it could be an issue with the alpha.


Localized country names not showing

In my Django admin back end the country names are showing in English, while the admin interface itself is shown in Dutch, like I configured.

It's probably a misconfiguration on my part, or I did not perform some action needed.

I installed django-countries using pip with Django 1.3.1 and my settings file contains the following:

#!python

LANGUAGES = [('nl', 'NL')]
LANGUAGE_CODE = 'nl'
TRANSMETA_DEFAULT_LANGUAGE = 'nl'
DEFAULT_LANGUAGE = 0

and django.core.context_processors.i18n is enabled.

Does anyone have some pointers on what I might try next?


Slow admin loading

I have a field of type CountryField. In the admin interface, when I use this field in the list display, it's incredibly slow to load when there are ~100 rows.

I've tried using list_select_related = ('country',), or even list_select_related = True, but there is no speedup (DDT doesn't report any extra queries with or without this - 5 in each case). However, there is significant speed increase when I use a filter (reducing the number of rows) or if I remove this field from the list display interface.

Is there any way to speed this up/cache the results?

Upload new translations

Hi,
I complete french translation from transifex and I saw last update on github was 5-7 months ago.
There's is no way to automatize download and push ? I have found this page : http://docs.transifex.com/developer/client/pull
Can you push all translation on repo ?

And I have not found how can I be a Rewiever on transifex.

Thank you ;)

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.