madisona / django-google-maps

Using the Google Maps API with django model admin
BSD 2-Clause "Simplified" License
281 stars 99 forks source link

Should it work on Python 3.8 and Django latest version ? #63

Closed fredericpierron closed 4 years ago

fredericpierron commented 4 years ago

Django Version: 2.2.7 Python Version: 3.8.0

Exception Type: OperationalError at /admin/wbmap/location/ Exception Value: (1054, "Unknown column 'wbmap_location.geolocation' in 'field list'")

madisona commented 4 years ago

it should - have you run your database migrations?

fredericpierron commented 4 years ago

yes, I have even flush and erase migrations to start fresh.

madisona commented 4 years ago

can you show what your model looks like? The tests pass under the versions you're using. https://travis-ci.org/github/madisona/django-google-maps

fredericpierron commented 4 years ago

Models.py uses:

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

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

and admin uses:

from django.contrib import admin
from django_google_maps import widgets as map_widgets
from django_google_maps import fields as map_field

class LocationAdmin(admin.ModelAdmin):
    formfield_overrides = {
        map_fields.AddressField: {'widget': map_widgets.GoogleMapsAddressWidget},
    }
fredericpierron commented 4 years ago

Full Models for your test:

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

class Subscriber(models.Model):
    login  = models.CharField(max_length=200, unique=True)
    email  = models.CharField(max_length=200, unique=True)
    country  = models.CharField(max_length=100)

    def __str__(self):
        return self.email

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

class Video(models.Model):
    video_title = models.CharField(max_length=200)
    video_url = models.CharField(max_length=255, unique=True)
    video_file = models.CharField(max_length=50)
    video_date = models.DateTimeField('date published')
    video_user = models.ForeignKey(Subscriber, on_delete=models.CASCADE)
    loc = models.ForeignKey(Location, on_delete=models.CASCADE)

    def __str__(self):
        return self.video_title + " / " + self.video_file

and full admin:

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 Video, Subscriber, Location

class VideoAdmin(admin.ModelAdmin):
    fields = [ 'video_title', 'video_user', 'video_date', 'video_url', 'video_file' ]

class LocationAdmin(admin.ModelAdmin):
    formfield_overrides = {
        map_fields.AddressField: {'widget': map_widgets.GoogleMapsAddressWidget},
    }

admin.site.register(Location, LocationAdmin)
admin.site.register(Video, VideoAdmin)
admin.site.register(Subscriber)
madisona commented 4 years ago

and can you from the DBShell desc the location table to make sure it exists in the database?

fredericpierron commented 4 years ago
 ;
+---------+--------------+------+-----+---------+----------------+
| Field   | Type         | Null | Key | Default | Extra          |
+---------+--------------+------+-----+---------+----------------+
| id      | int(11)      | NO   | PRI | NULL    | auto_increment |
| name    | varchar(100) | NO   |     | NULL    |                |
| gps     | point        | NO   | MUL | NULL    |                |
| address | varchar(100) | NO   |     | NULL    |                |
| city    | varchar(50)  | NO   |     | NULL    |                |
+---------+--------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
madisona commented 4 years ago

Ok - there isn't a field called geolocation which is why you're getting the error. Exception Value: (1054, "Unknown column 'wbmap_location.geolocation' in 'field list'")

fredericpierron commented 4 years ago

ok, so you mean my field gps should be renamed geolocation to work? I give a try.

fredericpierron commented 4 years ago

Ok, after erasing by hand all migrations, databas, table, caches, ... I've recreated the models, with geolocation in name of the field and the admin works almost. The map does not appears (maybe a bad Gmap key? to be checked). Thanks.

fredericpierron commented 4 years ago

OK, now it works. Static files were missing. As I've installed through pip, i thought everything would come in the right place. After creating folder for static, it's okay now.

Thanks for your help.

madisona commented 4 years ago

you bet - good luck with your project