Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
from django.contrib import admin
from .models import Author, Book
class BookInline(admin.TabularInline):
model = Book
readonly_fields = ['slug']
class AuthorAdmin(admin.ModelAdmin):
inlines = [BookInline]
admin.site.register(Author, AuthorAdmin)
from django.db import models
from django.template.defaultfilters import slugify
class Author(models.Model):
name = models.CharField(max_length=200)
def __unicode__(self):
return self.name
class Book(models.Model):
author = models.ForeignKey(Author)
slug = models.SlugField(primary_key=True)
title = models.CharField(max_length=200)
def __unicode__(self):
return self.title
def save(self, **kwargs):
if not self.slug:
self.slug = slugify(self.title)
super(Book, self).save(**kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.