2

I get an error when I display a form in django admin (update form):

Uncaught ReferenceError: django is not defined

The error is in the lines below:

(function($) {
  $("#participations-group .tabular.inline-related tbody tr").tabularFormset({
    prefix: "participations",
    adminStaticPrefix: '/static/admin/',
    addText: "Ajouter un objet Participation À Une Campagne supplémentaire",
    deleteText: "Supprimer"
  });
})(django.jQuery);

The code was generated by django.

In my admin form, I am using a js file:

class CampaignAdmin(admin.ModelAdmin):
    class Media:
        js = (
            'js/admin/campaign.min.js',
        )

As proposed in this post https://stackoverflow.com/a/10584539/1875861, I have added two js files:

class CampaignAdmin(admin.ModelAdmin):
    class Media:
        js = (
            'admin/js/jquery.min.js',
            'admin/js/jquery.init.js',
            'js/admin/campaign.min.js',
        )

But it still does not work :(.

What is the problem?

Community
  • 1
  • 1
rom
  • 3,592
  • 7
  • 41
  • 71
  • You have this in your first Js code snippet `django.jQuery`. Pretty sure jQuery doesn't belong to django here. – Aaron Lelevier Jan 21 '16 at 01:48
  • Ok then another developer wrote this code... Should I remove django.jQuery or include jquery somewhere? – rom Jan 21 '16 at 07:39

1 Answers1

0

If you are using 1.9 or 1.8 you don't need to add jquery to your js media: see: https://docs.djangoproject.com/en/1.9/ref/contrib/admin/#contrib-admin-jquery

Have you tried this config, by any chance?

(function($){
    $(document).ready(function(){
        $("#participations-group .tabular.inline-related tbody tr").tabularFormset({
          prefix: "participations",
          adminStaticPrefix: '/static/admin/',
          addText: "Ajouter un objet Participation À Une Campagne supplémentaire",
          deleteText: "Supprimer"
        });
        });
    });
}(django.jQuery));

I followed this post: http://coreymaynard.com/blog/adding-jquery-event-listeners-to-dynamically-creat/

Clémentine
  • 468
  • 1
  • 5
  • 16