0Pricing
Django Academy · レッスン

admin.siteにモデルを登録する

管理画面でモデルを編集できるようにします

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

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

Empty Dashboard

Right now the admin only shows Users and Groups. To manage your own data you must register each model so the admin knows about it.

Where to Register

Each app has its own admin.py file. This is the one place you tell Django which models should appear in the admin.

Import the Tool

First bring in the admin module. The admin object is your gateway to registering models and customizing the site.

from django.contrib import admin

Import Your Model

Next import the model you want to manage. Pull it in from your app's models module so admin.py can reference it.

from .models import Post

Register It

Now hand the model to the admin. Calling admin.site.register() adds that model straight onto the dashboard.

admin.site.register(Post)

See It Appear

Refresh /admin and your model is now listed with built-in add, edit, and delete screens. No extra views needed. ✨

Register Many

Got several models? Just import each one and call register again. Every register call gives that model its own admin section.

admin.site.register(Author)
admin.site.register(Tag)

The Decorator Way

There is a cleaner style too. The @admin.register decorator registers a model right above its admin class in one step.

@admin.register(Post)
class PostAdmin(admin.ModelAdmin):
    pass

Friendly Names

The admin shows each row using the model's __str__ method. A good __str__ turns cryptic rows into readable labels.

def __str__(self):
    return self.title

Already Registered

Register the same model twice and Django raises AlreadyRegistered. Each model belongs to exactly one register call.

Restart Not Needed

The dev server auto-reloads when you save admin.py, so just refresh the page. Your newly registered model shows up instantly.

Quick Check

How do you make a model appear in the admin?

Recap

In admin.py you imported a model and registered it, and it appeared on the dashboard with full CRUD screens. That is the core admin workflow. 🎉

よくある質問

「admin.siteにモデルを登録する」レッスンは無料ですか?

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

「admin.siteにモデルを登録する」で何を学びますか?

管理画面でモデルを編集できるようにします ブラウザで直接実行するハンズオンコードでDjango Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

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

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

「admin.siteにモデルを登録する」レッスンにはどのくらい時間がかかりますか?

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

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

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

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

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