Memasang Django-Grappelli

Bosan dengan tampilan default dari django-admin? Gunakan django-grappelli.

https://django-grappelli.readthedocs.io/en/latest/index.html

Drawbacks:

  1. fungsi prepulated_fields untuk slug tidak jalan, terpaksa harus menggunakan cara manual dengan meng-override fungsi save di models.py. Contoh:
from django.db import Models
from django.template.defaultfilters import slugify
from django.utils.translation import ugettext_lazy as _


class Rumah(models.Model):
    """Rumah models."""

    judul_iklan = models.CharField(
        max_length=255,
        help_text=_('Masukkan judul iklan')
    )
    judul_iklan_slug = models.SlugField(
        help_text=_('Otomatis terisi, biarkan saja')
    )

    def save(self, *args, **kwargs):
        # override save for judul_iklan_slug field
        self.judul_iklan_slug = slugify(self.judul_iklan)
        super(Rumah, self).save(*args, **kwargs)

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s