Commits

hideki nara committed c63122f

Prefecture , to_json

Comments (0)

Files changed (3)

src/djpostal/admin.py

 from django.contrib import admin
 from models import *
 
+class PrefectureAdmin(admin.ModelAdmin):
+    list_display=tuple([f.name for f in Prefecture._meta.fields])
+
+admin.site.register(Prefecture,PrefectureAdmin )
+
 class JpAddressAdmin(admin.ModelAdmin):
     list_display=tuple([f.name for f in JpAddress._meta.fields])
 

src/djpostal/models.py

 
 from django.db import models
 
+class Prefecture(models.Model):
+    ''' 都道府県 '''
+    name = models.CharField(max_length=50,db_index=True,unique=True,)   
+    kana = models.CharField(max_length=50,db_index=True,unique=True,)
+
+    class Meta:
+        verbose_name =u'都道府県'
+        verbose_name_plural =u'都道府県'
+
+#>>> for i in  JpAddress.objects.values('prefecture','prefecture_kana').distinct() :
+#...     Prefecture(name=i['prefecture'],kana=i['prefecture_kana']).save()
+
+        
 class JpAddress(models.Model):
     code = models.CharField(max_length=10,db_index=True,unique=False)
     zip5 = models.CharField(max_length=5 )

src/djpostal/utils.py

                             encoding=encoding, 
                                 errors=errors , **kwds)
         return enumerate(csvreader)
+
+from collections import Iterable
+def to_json(data,ascii=False,indent=2):
+    ''' JSON fixture '''
+    data = data if isinstance(data,Iterable) else [data]
+    return serializers.serialize("json",data, ensure_ascii,indent=indent)