Sets default value for district corporation field
This commit is contained in:
parent
02fb84700f
commit
ec4a3592ff
2 changed files with 37 additions and 3 deletions
|
|
@ -215,13 +215,21 @@ class ContactInline(admin.StackedInline):
|
|||
|
||||
|
||||
class CorporationAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'short_name', 'pcode', 'city', 'ext_id')
|
||||
list_display = ('name', 'short_name', 'pcode', 'city', 'district', 'ext_id')
|
||||
list_editable = ('short_name',) # Temporarily?
|
||||
list_filter = (('archived', ArchivedListFilter),)
|
||||
search_fields = ('name', 'street', 'pcode', 'city')
|
||||
ordering = ('name',)
|
||||
fields = (('name', 'short_name'), 'parent', ('sector', 'typ', 'ext_id'),
|
||||
'street', ('pcode', 'city'), ('tel', 'email'), 'web', 'archived')
|
||||
fields = (
|
||||
('name', 'short_name'),
|
||||
'parent',
|
||||
('sector', 'typ', 'ext_id'),
|
||||
'street',
|
||||
('pcode', 'city', 'district'),
|
||||
('tel', 'email'),
|
||||
'web',
|
||||
'archived',
|
||||
)
|
||||
inlines = [ContactInline]
|
||||
|
||||
def get_search_results(self, request, qs, term):
|
||||
|
|
|
|||
26
stages/migrations/0016_populate_corp_district.py
Normal file
26
stages/migrations/0016_populate_corp_district.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
from django.db import migrations
|
||||
|
||||
|
||||
def populate_district(apps, schema_editor):
|
||||
Corporation = apps.get_model('stages', 'Corporation')
|
||||
|
||||
for corp in Corporation.objects.filter(district=''):
|
||||
pcode = int(corp.pcode)
|
||||
if pcode in range(2000, 2334) or pcode in range(2400, 2417) or pcode in [2523, 2525, 2616]:
|
||||
corp.district = 'NE'
|
||||
corp.save()
|
||||
elif pcode in range(2336, 2365) or pcode in range(2714, 2719) or pcode in range(2800, 2955):
|
||||
corp.district = 'JU'
|
||||
corp.save()
|
||||
elif pcode in [2333, 2346] or pcode in range(2500, 2521) or pcode in range(2532, 2763) or pcode in range(3000, 3865):
|
||||
corp.district = 'BE'
|
||||
corp.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('stages', '0015_added_supervision_attest_field'),
|
||||
]
|
||||
|
||||
operations = [migrations.RunPython(populate_district)]
|
||||
Loading…
Add table
Add a link
Reference in a new issue