... が必要です (CSV ファイルは使えません!)。これらは、例えば MaxMind や DB-IP のウェブサイトからダウンロードできます。 GeoLite2-Country.mmdb.gz および GeoLite2-City.mmdb.gz ファイルを取得し、これらを GEOIP_PATH 設定に対応するディレクトリに解凍してください。 ... すめします。 カスタマイズ例 以下はその使用例です: >>> from django.contrib.gis.geoip2 import GeoIP2 >>> g = GeoIP2 () >>> g . country ( "google.com" ) {'continent_code': 'NA', 'continent_name': 'North America', 'country_code': 'US', 'country_name': 'United ... 4.207.99" ) {'accuracy_radius': 1000, 'city': 'Mountain View', 'continent_code': 'NA', 'continent_name': 'North America', 'country_code': 'US', 'country_name': 'United States', 'is_in_european_union': False, 'latitude': 37.419200897216797, 'longitude': ... ... ブジェクトのグループを作ります。 この複雑なタグは例を通して説明するのがいいでしょう: cities は "name" , "population" , and "country" をキーとして含むディクショナリによって表された都市のリストとします: cities = [ { "name" : "Mumbai" , "population" : "19,0 ... 00,000" , "country" : "India" }, { "name" : "Calcutta" , "population" : "15,000,000" , "country" : "India" }, { "name" : "New York" , "popula ... tion" : "20,000,000" , "country" : "USA" }, { "name" : "Chicago" , "population" : "7,000,000" , "country" : "USA" }, { "name" : "Tokyo" , "population" : " ... ... ンファイルの Migration クラスから独立した別の関数として記述し、 RunPython に渡すことを推奨します。以下に RunPython を用いて Country モデル上の初期オブジェクトを追加する例を示します: from django.db import migrations def forwards_func ( apps , schema_edito ... r ): # We get the model from the versioned app registry; # if we directly import it, it'll be the wrong version Country = apps . get_model ( "myapp" , "Country" ) db_alias = schema_editor . connection . alias Country . objects . using ( db_al ... ias ) . bulk_create ( [ Country ( name = "USA" , code = "us" ), Country ( name = "France" , code = "fr" ), ] ) def reverse_func ( apps , schema_editor ): ... ... 違いは、フォームフィールドの選択肢を入力するためにデータベースクエリを作成することです: class LocationForm ( forms . Form ): country = forms . ChoiceField ( choices = [ c . name for c in Country . objects . all ()]) 上の例では、 QuerySet がイテレートされる ... ため、 Country.objects.all() からのクエリがモジュールのインポート時に実行されます。警告を回避するには、代わりに ModelChoiceField を使用し ... ます: class LocationForm ( forms . Form ): country = forms . ModelChoiceField ( queryset = Country . objects . all ()) この警告を引き起こしたコードを見つけやすくするために、 ... ... 標に関する追加情報にアクセスしたい時は、次のように実装します。 class GPSCoordinatesBoundField ( BoundField ): @property def country ( self ): """ Return the country the coordinates lie in or None if it can't be determined. """ value = self . value () if ... value : return get_country_from_coordinates ( value ) else : return None class GPSCoordinatesField ( Field ): bound_field_class = GPSCoordinatesBound ... Field これで、テンプレート内で {{ form.coordinates.country }} を使って国にアクセスできるようになりました。 デフォルトのフォームフィールドのテンプレートレンダリングをカスタマイズした ... ... のクラス) Count (django.db.models のクラス) count (Paginator の属性) count() (django.db.models.query.QuerySet モジュール) country() (GeoIP2 のメソッド) country_code() (GeoIP2 のメソッド) country_name() (GeoIP2 のメソッド) coupling loose CovarPop (djang ... rib.gis.db.models.functions のクラス) GeoIP2 (django.contrib.gis.geoip2 のクラス) GeoIP2Exception GEOIP_CITY setting GEOIP_COUNTRY setting GEOIP_PATH setting geojson (GEOSGeometry の属性) geom (Feature の属性) geom_count (OGRGeometry の属性) geom_name ( ... ... ield ): def __init__ ( self , ** kwargs ): # Define one message for all fields. error_messages = { "incomplete" : "Enter a country calling code and a phone number." , } # Or define a different message for each field. fields = ( CharField ( error_message ... s = { "incomplete" : "Enter a country calling code." }, validators = [ RegexValidator ( r "^[0-9]+$" , "Enter a valid country calling code." ), ], ), CharField ... ... ld () revenue = forms . DecimalField ( max_digits = 4 , decimal_places = 2 , localize = True ) Locale specific helpers For country specific form fields, validation, and data formats that are not included in Django itself, consider using the django-local ... ... GeoIP2 が、 ipaddress.IPv4Address または ipaddress.IPv6Address オブジェクトを使用してクエリできるようになりました。 GeoIP2.country() が continent_code 、 continent_name 、 is_in_european_union の値を公開するようになりました。 GeoIP2.city() は、 accuracy ... ... ( max_length = 50 ) city = models . CharField ( max_length = 60 ) state_province = models . CharField ( max_length = 30 ) country = models . CharField ( max_length = 50 ) website = models . URLField () class Meta : ordering = [ "-name" ] def __str__ ( ... 2026年10月08日