From 4316ab6f2be81b1013a51ceaf1cddfae7b94036d Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 5 Mar 2021 13:13:49 +0000 Subject: [PATCH] showing googlemaps in company admin --- back_latienda/settings/base.py | 11 +++++++++++ companies/admin.py | 7 +++++++ companies/models.py | 2 +- example.env | 4 +++- requirements.txt | 1 + 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/back_latienda/settings/base.py b/back_latienda/settings/base.py index cdb5888..d7249b5 100644 --- a/back_latienda/settings/base.py +++ b/back_latienda/settings/base.py @@ -56,6 +56,7 @@ INSTALLED_APPS = [ 'tagulous', 'anymail', 'storages', + 'mapwidgets', # local apps 'core', @@ -159,3 +160,13 @@ TAXONOMY_FILE = 'shop-taxonomy.es-ES.txt' MEDIA_URL = '/media/' MEDIA_ROOT = BASE_DIR + '/../media/' GEOIP_PATH = BASE_DIR + '/../datasets/' + +MAP_WIDGETS = { + "GooglePointFieldWidget": ( + ("zoom", 6), + ("mapCenterLocationName", "madrid"), + ("GooglePlaceAutocompleteOptions", {'componentRestrictions': {'country': 'es'}}), + ("markerFitZoom", 12), + ), + "GOOGLE_MAP_API_KEY": os.getenv('GOOGLE_MAP_API_KEY') +} diff --git a/companies/admin.py b/companies/admin.py index d45188c..5dd4451 100644 --- a/companies/admin.py +++ b/companies/admin.py @@ -1,4 +1,7 @@ from django.contrib import admin +from django.contrib.gis.db.models import PointField + +from mapwidgets.widgets import GooglePointFieldWidget from . import models @@ -9,5 +12,9 @@ class CompanyAdmin(admin.ModelAdmin): list_filter = ('platform', 'sync', 'is_validated', 'is_active', 'city') search_fields = ('short_name', 'company_name', 'email', 'url') + formfield_overrides = { + PointField: {"widget": GooglePointFieldWidget} + } + admin.site.register(models.Company, CompanyAdmin) diff --git a/companies/models.py b/companies/models.py index a866975..84baff0 100644 --- a/companies/models.py +++ b/companies/models.py @@ -51,7 +51,7 @@ class Company(models.Model): # internal created = models.DateTimeField('date of creation', auto_now_add=True) updated = models.DateTimeField('date last update', auto_now=True) - creator = models.ForeignKey('core.CustomUser', on_delete=models.DO_NOTHING, null=True, related_name='creator') + creator = models.ForeignKey('core.CustomUser', on_delete=models.DO_NOTHING, null=True, blank=True, related_name='creator') # history = models.ForeignKey(HistorySync, null=True, on_delete=models.DO_NOTHING, related_name='company') class Meta: diff --git a/example.env b/example.env index a2ad913..66a53de 100644 --- a/example.env +++ b/example.env @@ -12,4 +12,6 @@ AWS_ACCESS_KEY_ID_SES = '' AWS_SECRET_ACCESS_KEY_SES = '' # WooCommerce test credentials WC_KEY = '' -WC_SECRET = '' \ No newline at end of file +WC_SECRET = '' +# GOOGLE MAPS +GOOGLE_MAP_API_KEY = '' \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 5b07f13..ad2f270 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,6 +16,7 @@ geoip2==4.1.0 woocommerce==2.1.1 django-autocomplete-light==3.8.2 # manually install `pip install --default-timeout=100 future` to avoid wcapi to timeout +django-map-widgets==0.3.0 # required for production django-anymail[amazon_ses]==8.2 boto3==1.17.11