Ticket #11251: au-models.diff

File au-models.diff, 2.6 KB (added by Simon Meers <DrMeers@…>, 6 years ago)

Patch which provides django.contrib.localflavor.au.models and associated documentation.

  • django/contrib/localflavor/au/models.py

     
     1from django.conf import settings
     2from django.db.models.fields import Field
     3from django.contrib.localflavor.au import forms
     4
     5class AUStateField(Field):
     6    def get_internal_type(self):
     7        return "AUStateField"
     8       
     9    def db_type(self):
     10        if settings.DATABASE_ENGINE == 'oracle':
     11            return 'CHAR(3)'
     12        else:
     13            return 'varchar(3)'
     14   
     15    def formfield(self, **kwargs):
     16        defaults = {'widget': forms.AUStateSelect}
     17        defaults.update(kwargs)
     18        return super(AUStateField, self).formfield(**defaults)
     19
     20class AUPhoneNumberField(Field):
     21    def get_internal_type(self):
     22        return "AUPhoneNumberField"
     23
     24    def db_type(self):
     25        if settings.DATABASE_ENGINE == 'oracle':
     26            return 'VARCHAR2(10)'
     27        else:
     28            return 'varchar(10)'
     29
     30    def formfield(self, **kwargs):
     31        defaults = {'form_class': forms.AUPhoneNumberField}
     32        defaults.update(kwargs)
     33        return super(AUPhoneNumberField, self).formfield(**defaults)
     34
     35
     36class AUPostCodeField(Field):
     37    def get_internal_type(self):
     38        return "AUPostCodeField"
     39
     40    def db_type(self):
     41        if settings.DATABASE_ENGINE == 'oracle':
     42            return 'CHAR(4)'
     43        else:
     44            return 'varchar(4)'
     45
     46    def formfield(self, **kwargs):
     47        defaults = {'form_class': forms.AUPostCodeField}
     48        defaults.update(kwargs)
     49        return super(AUPostCodeField, self).formfield(**defaults)
  • docs/ref/contrib/localflavor.txt

     
    157157    A ``Select`` widget that uses a list of Australian states/territories as its
    158158    choices.
    159159
     160.. class:: au.models.AUPhoneNumberField
     161
     162    A model field that checks that the value is a valid Australian phone
     163    number (ten digits).
     164
     165.. class:: au.models.AUStateField
     166
     167    A model field that forms represent as a ``forms.AUStateField`` field and
     168    stores the three-letter Australian state abbreviation in the database.
     169
     170.. class:: au.models.AUPostCodeField
     171
     172    A model field that forms represent as a ``forms.AUPostCodeField`` field
     173    and stores the four-digit Australian postcode in the database.
     174
    160175Austria (``at``)
    161176================
    162177
Back to Top