2012-12-05 74 views
4

我是django新手。我需要一個谷歌地圖在我的模型。 1.我試圖用django-google-maps.my models.py是:django谷歌地圖

from django.db import models 
from django_google_maps import fields as map_fields 

class Rental(models.Model): 
    address = map_fields.AddressField(max_length=200) 
    geolocation = map_fields.GeoLocationField(max_length=200) 

和我的admin.py:

from django.contrib import admin 
from django_google_maps import widgets as map_widgets 
from django_google_maps import fields as map_fields 
from .models import Rental 

class RentalAdmin(admin.ModelAdmin): 
    formfield_overrides = { 
     map_fields.AddressField: {'widget': map_widgets.GoogleMapsAddressWidget}, 
    } 
admin.site.register(Rental, RentalAdmin) 

,但是當我點擊管理界面在地圖上字段仍然是空的。 我使用本指南來安裝它https://github.com/madisona/django-google-maps

2.我試圖用本指南使用easy-map http://pypi.python.org/pypi/django-easy-maps但我在管理界面中看不到地址預覽。 我的admin.py是:

from django import forms 
from django.contrib import admin 
from easy_maps.widgets import AddressWithMapWidget 
from .models import Address 

class AddressAdmin(admin.ModelAdmin): 
    class form(forms.ModelForm): 
     class Meta: 
      widgets = { 
       'address': AddressWithMapWidget({'class': 'vTextField'}) 
      } 

admin.site.register(Address, AddressAdmin) 

回答