| 714 | === Moved inner-model ```class Admin``` to ```ModelAdmin``` classes === |
| 715 | |
| 716 | The 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 |
| 723 | from django.db import models |
| 724 | |
| 725 | class MyModel(models.Model): |
| 726 | name = models.CharField(max_length=100) |
| 727 | |
| 728 | class Admin: |
| 729 | pass |
| 730 | |
| 731 | # NEW: |
| 732 | # models.py |
| 733 | from django.db import models |
| 734 | |
| 735 | class MyModel(models.Model): |
| 736 | name = models.CharField(max_length=100) |
| 737 | |
| 738 | # admin.py |
| 739 | from django.contrib import admin |
| 740 | from myproject.myapp.models import MyModel |
| 741 | |
| 742 | admin.site.register(MyModel) |
| 743 | }}} |
| 744 | |
| 745 | If 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 |
| 752 | from django.db import models |
| 753 | |
| 754 | class MyModel(models.Model): |
| 755 | name = models.CharField(max_length=100) |
| 756 | |
| 757 | class Admin: |
| 758 | list_display = ('name',) |
| 759 | |
| 760 | # NEW: |
| 761 | # models.py |
| 762 | from django.db import models |
| 763 | |
| 764 | class MyModel(models.Model): |
| 765 | name = models.CharField(max_length=100) |
| 766 | |
| 767 | # admin.py |
| 768 | from django.contrib import admin |
| 769 | from myproject.myapp.models import MyModel |
| 770 | |
| 771 | class MyModelAdmin(admin.ModelAdmin): |
| 772 | list_display = ('name',) |
| 773 | |
| 774 | admin.site.register(MyModel, MyModelAdmin) |
| 775 | }}} |
| 776 | |