philippbosch / django-geoposition

Django model field that can hold a geoposition, and corresponding widget
http://django-geoposition.rtfd.org/
MIT License
331 stars 204 forks source link

Django geoposition breaking prepopulate_fields? #38

Open Luis-Palacios opened 9 years ago

Luis-Palacios commented 9 years ago

Hey there i was going mad trying to find why my prepopulated_fields were not working i finally narrowed down to start removing fields from my model and when i removed the GeopositionField the prepopulated fields worked.

I am using django 1.7.4 and django-geoposition 0.2.2, my admin theme is django-suit 0.2.12

Here is my model:

# Create your models here.
class Project(models.Model):
    title = models.CharField(max_length=200)
    slug = models.SlugField()
    body = models.TextField()
    #if a comment this line it all works just fine
    location = GeopositionField()
    create = models.DateTimeField(auto_now_add=True)
    modified = models.DateTimeField(auto_now=True)
    user = models.ForeignKey(User, verbose_name="Created by", editable=False)

    def __str__(self):
        return self.title

    def get_absolute_url(self):
        return reverse('projects:project_detail', kwargs = {'slug':self.slug})

    class Meta:
        verbose_name = 'Project'
        verbose_name_plural = 'Projects'

and my admin.py

class ProjectAdmin(admin.ModelAdmin):
    list_display = ['title', 'user']
    prepopulated_fields = {'slug': ('title',)}

    def save_model(self, request, obj, form, change):
        obj.user = request.user
        admin.ModelAdmin.save_model(self, request, obj, form, change)

admin.site.register(Project, ProjectAdmin)

the error i get is in the index script where it does this:

  $(field.id).data('dependency_list', field['dependency_list'])
               .prepopulate(field['dependency_ids'], field.maxLength);

it says in the console that undefined is not a function, i did some debuggin and it was referring to prepopulated

mativs commented 9 years ago

Have you find a solution for this problem?

Luis-Palacios commented 9 years ago

sadly no

mativs commented 9 years ago

I have removed this

if (jQuery != undefined) {
   var django = {
       'jQuery': jQuery,
   }
}

from top of geoposition.js and is working fine!! :smile:

Hope it helps you