summaryrefslogtreecommitdiff
path: root/postgresqleu/countries/models.py
blob: ee820dd9e03280bc9aef795fb014b09dcc93d10d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from django.db import models
from django.utils.translation import gettext_lazy as _

class Country(models.Model):
    """
    International Organization for Standardization (ISO) 3166-1 Country list
    
     * ``iso`` = ISO 3166-1 alpha-2
     * ``name`` = Official country names used by the ISO 3166/MA in capital letters
     * ``printable_name`` = Printable country names for in-text use
     * ``iso3`` = ISO 3166-1 alpha-3
     * ``numcode`` = ISO 3166-1 numeric
    
    Note::
        This model is fixed to the database table 'country' to be more general.
        Change ``db_table`` if this cause conflicts with your database layout.
        Or comment out the line for default django behaviour.
    
    """
    iso = models.CharField(_('ISO alpha-2'), max_length=2, primary_key=True)
    name = models.CharField(_('Official name (CAPS)'), max_length=128)
    printable_name = models.CharField(_('Country name'), max_length=128)
    iso3 = models.CharField(_('ISO alpha-3'), max_length=3, null=True)
    numcode = models.PositiveSmallIntegerField(_('ISO numeric'), null=True)
    
    class Meta:
        db_table = 'country'
        verbose_name = _('Country')
        verbose_name_plural = _('Countries')
        ordering = ('name',)
        
    class Admin:
        list_display = ('printable_name', 'iso',)
        
    def __str__(self):
        return self.printable_name


class UsState(models.Model):
    """
    United States Postal Service (USPS) State Abbreviations
    
    Note::
        This model is fixed to the database table 'usstate' to be more general.
        Change ``db_table`` if this cause conflicts with your database layout.
        Or comment out the line for default django behaviour.
    
    """
    id = models.AutoField(primary_key=True)
    name = models.CharField(_('State name'), max_length=50, null=False)
    abbrev = models.CharField(_('Abbreviation'), max_length=2, null=False)

    class Meta:
        db_table = 'usstate'
        verbose_name = _('US State')
        verbose_name_plural = _('US States')
        ordering = ('name',)

    class Admin:
        list_display = ('name', 'abbrev',)

    def __str__(self):
        return self.name


# XXX: this table is added by pgeu :)
class EuropeCountry(models.Model):
    iso = models.OneToOneField(Country, null=False, blank=False, primary_key=True, on_delete=models.CASCADE)

    def __str__(self):
        return iso.name