0Pricing
Django Academy · レッスン

インラインと読み取り専用フィールド

関連する行をインラインで編集し、フィールドを保護します

「インラインと読み取り専用フィールド」はCoddyKit上の無料Django Academyレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはDjango Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Django Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Edit Related Rows Together

Sometimes related records belong on the same page. An inline lets you edit child rows right inside their parent's edit form. 🧩

Two Inline Styles

Django offers two layouts. A TabularInline shows rows in a compact table, while StackedInline stacks each row as its own block.

Define an Inline

Create a small class that subclasses TabularInline and points its model attribute at the child model you want to embed.

class CommentInline(admin.TabularInline):
    model = Comment

Attach to the Parent

List your inline on the parent's admin. The inlines option tells Django to render those child rows inside the parent form.

class PostAdmin(admin.ModelAdmin):
    inlines = [CommentInline]

Spare Blank Rows

Inlines show empty rows for quick adding. Set extra to control how many blank slots appear, often just one is enough.

extra = 1

The FK Requirement

Inlines only work when the child has a ForeignKey to the parent. That link is how Django knows which rows belong together.

Protect a Field

Some values should be visible but never edited by hand. Add them to readonly_fields and the admin shows them locked. 🔒

readonly_fields = ("created", "updated")

Auto Timestamps

Fields like an auto_now_add date are set by Django, not people. Marking them readonly avoids confusing, unsaveable edits.

Show a Computed Value

readonly_fields can name a method too, letting you display a calculated value that has no real database column.

def word_count(self, obj):
    return len(obj.body.split())

Readonly Inside Inlines

Inlines accept readonly_fields as well. Use it to display child data clearly while keeping sensitive columns uneditable.

Permissions Still Apply

Readonly is about the form, not security. Real access is governed by user permissions, so combine both for safe editing.

Quick Check

What is required for a model to appear as an inline?

Recap

You embedded related rows with inlines and locked sensitive values using readonly_fields. Together they make admin editing rich yet safe. ✅

よくある質問

「インラインと読み取り専用フィールド」レッスンは無料ですか?

はい。「インラインと読み取り専用フィールド」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Django Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Django Academyコースには全4レッスンが含まれています。

「インラインと読み取り専用フィールド」で何を学びますか?

関連する行をインラインで編集し、フィールドを保護します ブラウザで直接実行するハンズオンコードでDjango Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Django Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのDjango Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「インラインと読み取り専用フィールド」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このDjango Academyレッスンでコードを書いて実行できますか?

はい。すべてのDjango Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. createsuperuserとログイン
  2. admin.siteにモデルを登録する
  3. ModelAdminをカスタマイズする
  4. インラインと読み取り専用フィールド
← Django Academyに戻る