# This Python file uses the following encoding: utf-8
# !/usr/bin/env python
import os

import django

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "proj_hkcm.settings")
django.setup()

from hkcm.models import Cmdata, DistrictsClassification

if __name__ == "__main__":
    """
    Purpose : update district fields in cmdata table.
    Author  : Pharrell.zx
    Date    : 2017 Feb 6 """

    list_of_crime_records = Cmdata.objects.all()
    list_of_classification_result = DistrictsClassification.objects.all()

    for x in list_of_crime_records:
        try:
            id_of_crime_record = x.id
            corresponding_entry_in_districts_classification = \
                DistrictsClassification.objects.get(id_in_cmdata=id_of_crime_record)

            dist = corresponding_entry_in_districts_classification.Districts

            x.district = dist

            x.save()
        except:
            print(x.id)
            print(type(x.district))
            x.district = "out_of_hk"
            x.save
