Skip to content

oertels/django-gfkajax

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

"gfkajax" = "Generic Foreign Keys with Ajax". Inspired by django-genericadmin (which does not work here, unfortunately). It converts the inconvenient generic key selection widget into a neat ajax-driven tool.

Installation

Install gfkajax and add gfkajax to INSTALLED_APPS.

In your root urls.py, add this line:

(r'^gfkajax/', include('gfkajax.urls')),

Usage

Create an admin.py as usual, and then change the ModelAdmin-class like this:

from gfkajax.forms import make_GfkAjaxForm

class FooAdmin(admin.ModelAdmin):
    form = make_GfkAjaxForm()
    [..]

You may pass gfkajax a whitelist containing allowed content types, in format "app_name.modelname_". The Admin form could look like this then:

from gfkajax.forms import make_GfkAjaxForm

class FooAdmin(admin.ModelAdmin):
    form = make_GfkAjaxForm(
        whitelist = [
            'myapp.mymodel_lowercased'
            'myappsecondapp.mysecondmodel_lowercased',
        ]
    )
    [..]

Advanced usage

You can tell gfkajax how to render selected objects. This is useful, if you offer e.g. images or videos as generic relations.

To do so, just add a "gfk_render()" method to your model, like:

class MyModel(models.Model):
    def gfk_render(self):
        return u'%s&nbsp;<img src="myimage.jpg" />&nbsp;' % self.mytitle

If your form needs additional fields, you can pass them as.. "additional_fields":

    form = make_GfkAjaxForm(
        whitelist = [
            'myapp.mymodel_lowercased'
            'myappsecondapp.mysecondmodel_lowercased',
        ],
        additional_fields=[
            'my_field': AutoCompleteSelectMultipleField('foo', required=False)
        ],
    )
    [..]

Todo

  • Related objects must be removable
  • Make translatable
  • Add example project

About

Django generic foreign keys with ajax

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published