Changes between Version 240 and Version 241 of BackwardsIncompatibleChanges


Ignore:
Timestamp:
Aug 21, 2008, 2:59:17 PM (16 years ago)
Author:
Brian Rosner
Comment:

fixed #8474. added an explicit example of the ModelAdmin.

Legend:

Unmodified
Added
Removed
Modified
  • BackwardsIncompatibleChanges

    v240 v241  
    712712Previously, there was one "global" version of the admin site, which used all models that contained a {{{class Admin}}}. This new scheme allows for much more fine-grained control over your admin sites, allowing you to have multiple admin sites in the same Django instance.
    713713
     714=== Moved inner-model ```class Admin``` to ```ModelAdmin``` classes ===
     715
     716The syntax to define your models in the admin has changed slightly. It is now longer in your model and is instead in an application level ```admin.py``` module. Here is a quick example showing you the change:
     717
     718{{{
     719#!python
     720
     721# OLD:
     722# models.py
     723from django.db import models
     724
     725class MyModel(models.Model):
     726    name = models.CharField(max_length=100)
     727
     728    class Admin:
     729        pass
     730
     731# NEW:
     732# models.py
     733from django.db import models
     734
     735class MyModel(models.Model):
     736    name = models.CharField(max_length=100)
     737
     738# admin.py
     739from django.contrib import admin
     740from myproject.myapp.models import MyModel
     741
     742admin.site.register(MyModel)
     743}}}
     744
     745If your old inner admin class defined options that controlled the behavior of the admin they have moved to class level in a ```ModelAdmin``` class. All options are the same with the exception of the ones noted in this section below.
     746
     747{{{
     748#!python
     749
     750# OLD:
     751# models.py
     752from django.db import models
     753
     754class MyModel(models.Model):
     755    name = models.CharField(max_length=100)
     756
     757    class Admin:
     758        list_display = ('name',)
     759
     760# NEW:
     761# models.py
     762from django.db import models
     763
     764class MyModel(models.Model):
     765    name = models.CharField(max_length=100)
     766
     767# admin.py
     768from django.contrib import admin
     769from myproject.myapp.models import MyModel
     770
     771class MyModelAdmin(admin.ModelAdmin):
     772    list_display = ('name',)
     773
     774admin.site.register(MyModel, MyModelAdmin)
     775}}}
     776
    714777=== Changed Admin.manager option to more flexible hook ===
    715778
Back to Top