Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatible with django-v1.10 #43

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions genericadmin/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def get_generic_field_list(self, request, prefix=''):
fields['prefix'] = prefix
field_list.append(fields)
else:
for field in self.model._meta.virtual_fields:
# for field in self.model._meta.virtual_fields:
for field in self.model._meta.private_fields:
if isinstance(field, GenericForeignKey) and \
field.ct_field not in exclude and field.fk_field not in exclude:
field_list.append({
Expand All @@ -74,11 +75,10 @@ def get_generic_field_list(self, request, prefix=''):
})

if hasattr(self, 'inlines') and len(self.inlines) > 0:
for FormSet, inline in zip(self.get_formsets(request), self.get_inline_instances(request)):
for FormSet, inline in self.get_formsets_with_inlines(request):
if hasattr(inline, 'get_generic_field_list'):
prefix = FormSet.get_default_prefix()
field_list = field_list + inline.get_generic_field_list(request, prefix)

return field_list

def get_urls(self):
Expand All @@ -90,10 +90,12 @@ def wrapper(*args, **kwargs):
custom_urls = [
url(r'^obj-data/$', wrap(self.generic_lookup), name='admin_genericadmin_obj_lookup'),
url(r'^genericadmin-init/$', wrap(self.genericadmin_js_init), name='admin_genericadmin_init'),
url(r'^(\d+)/obj-data/$', wrap(self.generic_lookup), name='admin_genericadmin_obj_lookup_change'),
url(r'^(\d+)/genericadmin-init/change/$', wrap(self.genericadmin_js_init), name='admin_genericadmin_init_change'),
]
return custom_urls + super(BaseGenericModelAdmin, self).get_urls()

def genericadmin_js_init(self, request):
def genericadmin_js_init(self, request, pk=None):
if request.method == 'GET':
obj_dict = {}
for c in ContentType.objects.all():
Expand All @@ -115,10 +117,10 @@ def genericadmin_js_init(self, request):
return HttpResponse(resp, content_type='application/json')
return HttpResponseNotAllowed(['GET'])

def generic_lookup(self, request):
def generic_lookup(self, request, pk=None):
if request.method != 'GET':
return HttpResponseNotAllowed(['GET'])

if 'content_type' in request.GET and 'object_id' in request.GET:
content_type_id = request.GET['content_type']
object_id = request.GET['object_id']
Expand Down
8 changes: 7 additions & 1 deletion genericadmin/static/genericadmin/js/genericadmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@
},

getLookupUrl: function(cID) {
return '../../../' + this.url_array[cID][0] + '/' + this.getLookupUrlParams(cID);
var forword = '../../../';
var suffix = '/change/';
var href = window.location.href;
if (href.indexOf(suffix, href.length - suffix.length) !== -1) {
forword += '../';
}
return forword + this.url_array[cID][0] + '/' + this.getLookupUrlParams(cID);
},

getFkId: function() {
Expand Down