2017-10-18 3 views
1

평소와 같이 admin.py에 자연스럽게 추가하려고했습니다. 기본 GeoModelAdmin을 OSMGeoAdmin으로 변경하십시오.

from django.contrib.gis import admin 
from project.models import ProjectMap 

admin.site.register(ProjectMap, admin.OSMGeoAdmin) 

나는 위젯 지정 시도 :

content_panels = Page.content_panels + [ 
    FieldPanel('location', widget='django.contrib.gis.forms.widgets.OSMWidget'), 
] 

을하지만 STIL GeoModelAdmin에서 기본 위성 이미지를 보여줍니다.

다음은 내가 작업중인 기본 모델입니다.

class ProjectPage(Page): 
    date = models.DateField("Post date", null=True) 
    body = RichTextField(blank=True) 

    def main_image(self): 
     gallery_item = self.gallery_images.first() 
     if gallery_item: 
      return gallery_item.image 
     else: 
      return None 

    search_fields = Page.search_fields + [ 
     index.SearchField('body'), 
    ] 

    content_panels = Page.content_panels + [ 
     MultiFieldPanel([ 
      FieldPanel('date'), 
     ], heading="Project information"), 
     MultiFieldPanel([ 
      FieldPanel('body', classname="full"), 
     ], heading='Project'), 
     InlinePanel('gallery_images', label="Gallery images"), 
     InlinePanel('project_map', label="Project location") 
    ] 


class ProjectMap(Orderable): 
    page = ParentalKey(ProjectPage, related_name='project_map') 
    city = models.CharField(blank=True, max_length=250) 
    address = models.CharField(blank=True, max_length=250) 
    country = models.CharField(blank=True, max_length=250) 
    location = PointField(blank=True, null=True) 

    content_panels = Page.content_panels + [ 
     MultiFieldPanel([ 
      FieldPanel('city'), 
      FieldPanel('address'), 
      FieldPanel('country'), 
      FieldPanel('location'), 
     ], heading="Location") 
    ] 

그리고 문서 내가 다음하고는 :

+2

FieldPanel''에'widget' 인수가 위젯 객체가 될 필요가 또는를 클래스가 아닌 문자열 경로 -'django.contrib.gis.forms.widgets import OSMWidget'과'FieldPanel ('location', widget = OSMWidget)'을 시도 할 수 있습니까? – gasman

답변

1

@gasman 올바른 것입니다!

당신은 당신이 객체가 전달되는 것을 볼이 아니라 문자열 것 specifying widgets에 대한 장고 문서를 살펴 걸릴 경우

from django.contrib.gis.forms.widgets import OSMWidget 

content_panels = Page.content_panels + [FieldPanel('location', widget=OSMWidget),] 
+0

감사합니다. 코드를 업데이트했습니다. 오류는 없지만 관리자는 위젯을 변경하지 않습니다. –

+0

ProjectMap이 ProjectPage의 부모 키 였기 때문에 작동하지 않았습니다. 그렇지 않은 경우 작동합니다. –

관련 문제