abidibo.net

Posted in "django-admin"

How to customize django change form redirect url

django-admin django

Sometimes may happen you need to customize a bit more than usual your django admin interface. Maybe because you need a different dashboard approach, or you just need to aggregate functionalities in a way which differs from a pure CRUD interface. Anyway, if possible, you try to keep the change and delete form code of the django admin, because you really are too lazy to rewrite all the add/change/delete stuff.

In such a situation I found myself searching ...

read the full post



Add app's contents inside ckeditor with django-resckeditor

ckeditor django django-admin

I always use django-ckeditor in my web site projects when I need an html editor. CKEditor is a nice tool, highly customizable, which produces a well formatted html. Here at Otto srl there was the need to include custom app's contents inside the editor in an easy way, since the tool has to be used by unexperienced people.

I approached these requirements developing a custom CKEditor plugin, which can communicate with django apps async through ajax requests. Every app can ...

read the full post


Django Baton, a cool, modern and responsive admin app

django django-admin programming

I was a happy developer using django-suit for all my working projects. Now django-suit v1 is becoming a bit oldie, it is based on bootstrap 2.3, and rewrites so many templates that its compatibility with some other apps begins to suffer (i.e. django-filer). It's a shame, it was in my opinion the best admin app overthere.

I know django-suit v2 is on stage, at the moment of this writing it is in development, and I'm quite sure it'will ...

read the full post


Show google analytics statistics in django admin

django django-admin

In this post we'll see how to show google analytics statistics inside your admin index. If you use django-suit as your admin application then you could simply install django-otto-admin and follow the provided instructions to get it working.

Requirements

First of all we need to create a google developer project and a service account which will allow us to authenticate to the google analytics account.

Follow the steps in the Google Identity Platform documentation to create a service account from the Google Developer Console.

Once the service account is created, you can click the Generate New JSON Key button to create and download the key and add it to your project. Place the json file in a secure place, not ...

read the full post


How to exclude choices of m2m raw_id_field in django admin

django programming django-admin

This procedure took a lot of effort to be understood, but now it seems quite easy.

Scenario

Imagine we need to create a recursive m2m relationship, something like a "related posts" field assigned to a Post model. It would be nice if we could exclude the current editing post from the available choices.

This is quite straightforward if we go with the default select multiple widget. In fact we only need to create a custom form class and override the queryset property of the related_posts field in the __init__ function, excluding the id of the current instance, and then assign such form class in the ModelAdmin class, see this SO question for more info.

But things become more ...

read the full post


Pretty raw_id_fields with django-salmonella and django-grappelli

django django-admin programming tips grappelli

Sometimes, when dealing with m2m relationships, we need to use the raw_id_fields property of the ModelAdmin class, in order to choose the related objects in a new page, where we can sort and filter the available items.

Without doubt the information that the widget used by django to treat such fields gives us is a bit poor. We only see the related objects's ids, it would be nicer to have the string representation of the object.

Here comes django-salmonella:

A raw_id_fields widget replacement that handles display of an object's string ...

read the full post


Add links to django admin changelist view

django django-admin programming tips

Sometimes you may need to add one or more links for each table row in your admin changelist view. There are many ways to do it, and here we'ss see a simple one. So this post is nothing more than a tip.

In my case I had to add a link opening a pdf view of the model item detail, here comes my implementation:

- app/models.py

from django.db import models
from django.core.urlresolvers import reverse
from django.utils.html import mark_safe

class MyModel(models.Model):
    title = models.CharField('title', max_length=255)
    # ...

    def pdf_link(self):
        return mark_safe('<a class="grp-button" href="%s" target="blank">view pdf</a>' % reverse('archiviocr-opera-pdf', args=[self.id]))
    pdf_link.short_description = _('PDF')

- app/admin ...

read the full post


Convert select multiple widget to checkboxes in django admin form

django django-admin django-mptt jquery

I think this should be a nice post talking about the substitution of the default multiple select widget used in django admin interface to deal with m2m fields, with a multiple checkbox widget.

Yes I know, you may solve it this way, but I don't like such solution very much, and I think it is just not perfect for some reasons:

  • At the time of this writing the add related functionality (+) seems to be broken, throws an error, at least for me
  • It just can't be used with the django-mptt application, which is awesome to deal with data which have a tree like structure

So to graphically explain what we want to do here, say we want this ...

read the full post


Using django-mptt TreeNodeChoiceField in a TabularInline admin form

django django-admin django-mptt

I use to use the django-mptt package to deal with tree like models. I also use to have my backoffice autogenerated by django admin.

Now one of the problems I've encountered was to add an inline form of a model which contains a "tree" field in a way the user can deal with a select input well formatted (showing parents and children in a clear way).

This task is easily reached in a normal form by defining the form ...

read the full post


Your Smartwatch Loves Tasker!

Your Smartwatch Loves Tasker!

Now available for purchase!

Featured