Skip to content

Commit

Permalink
Merge pull request #667 from awesto/adopt-polymorphic-ModelAdmin
Browse files Browse the repository at this point in the history
adopt polymorphic ModelAdmin-s to django-polymorphic>=1.0
  • Loading branch information
jrief committed Oct 23, 2017
2 parents ca15f89 + f503748 commit cf7e46c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
5 changes: 5 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ Changelog for django-SHOP
======

* Do not render buttons and links related to the watch-list, when it is not available.
* Fix: Adopt polymorphic ModelAdmin-s to django-polymorphic>=1.0.
* Use Sekizai's internal ``{% with_data ... %}`` to render Sekizai blocks ``ng-requires`` and
``ng-config`` rather than using the deprecated postprocessors ``djng.sekizai_processors.module_list``
and ``djng.sekizai_processors.module_config``. Adopt your templates accordingly as explained
in :ref:`reference/client-framework`
* Use Sekizai's internal templatetags ``{% with_data ... %}`` and ``{% with_data %}`` to render Sekizai
blocks ``ng-requires`` and ``ng-config`` rather than using the deprecated postprocessors
``djng.sekizai_processors.module_list`` and ``djng.sekizai_processors.module_config``. Adopt your
Expand Down
5 changes: 4 additions & 1 deletion example/myshop/admin/i18n_polymorphic.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from myshop.models.i18n_polymorphic.smartphone import OperatingSystem


@admin.register(Commodity)
class CommodityAdmin(SortableAdminMixin, TranslatableAdmin, FrontendEditableAdminMixin,
PlaceholderAdminMixin, CMSPageAsCategoryMixin, admin.ModelAdmin):
"""
Expand All @@ -42,6 +43,7 @@ class CommodityAdmin(SortableAdminMixin, TranslatableAdmin, FrontendEditableAdmi
prepopulated_fields = {'slug': ('product_name',)}


@admin.register(SmartCard)
class SmartCardAdmin(SortableAdminMixin, TranslatableAdmin, FrontendEditableAdminMixin,
CMSPageAsCategoryMixin, PlaceholderAdminMixin, PolymorphicChildModelAdmin):
base_model = Product
Expand All @@ -68,6 +70,7 @@ class SmartPhoneInline(admin.TabularInline):
extra = 0


@admin.register(SmartPhoneModel)
class SmartPhoneAdmin(SortableAdminMixin, TranslatableAdmin, FrontendEditableAdminMixin,
CMSPageAsCategoryMixin, PlaceholderAdminMixin, PolymorphicChildModelAdmin):
base_model = Product
Expand Down Expand Up @@ -104,7 +107,7 @@ def render_text_index(self, instance):
@admin.register(Product)
class ProductAdmin(PolymorphicSortableAdminMixin, PolymorphicParentModelAdmin):
base_model = Product
child_models = [(SmartPhoneModel, SmartPhoneAdmin), (SmartCard, SmartCardAdmin), (Commodity, CommodityAdmin)]
child_models = [SmartPhoneModel, SmartCard, Commodity]
list_display = ['product_name', 'get_price', 'product_type', 'active']
list_display_links = ['product_name']
search_fields = ['product_name']
Expand Down
11 changes: 7 additions & 4 deletions example/myshop/admin/polymorphic_.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from myshop.models.polymorphic_.smartphone import OperatingSystem


@admin.register(Commodity)
class CommodityAdmin(SortableAdminMixin, FrontendEditableAdminMixin, PlaceholderAdminMixin,
CMSPageAsCategoryMixin, admin.ModelAdmin):
"""
Expand All @@ -31,6 +32,7 @@ class CommodityAdmin(SortableAdminMixin, FrontendEditableAdminMixin, Placeholder
prepopulated_fields = {'slug': ['product_name']}


@admin.register(SmartCard)
class SmartCardAdmin(SortableAdminMixin, FrontendEditableAdminMixin,
CMSPageAsCategoryMixin, PlaceholderAdminMixin, PolymorphicChildModelAdmin):
base_model = Product
Expand All @@ -48,6 +50,7 @@ class SmartPhoneInline(admin.TabularInline):
extra = 0


@admin.register(SmartPhoneModel)
class SmartPhoneAdmin(SortableAdminMixin, FrontendEditableAdminMixin, CMSPageAsCategoryMixin,
PlaceholderAdminMixin, PolymorphicChildModelAdmin):
base_model = Product
Expand All @@ -74,10 +77,10 @@ def render_text_index(self, instance):
@admin.register(Product)
class ProductAdmin(PolymorphicSortableAdminMixin, PolymorphicParentModelAdmin):
base_model = Product
child_models = ((SmartPhoneModel, SmartPhoneAdmin), (SmartCard, SmartCardAdmin), (Commodity, CommodityAdmin),)
list_display = ('product_name', 'get_price', 'product_type', 'active',)
list_display_links = ('product_name',)
search_fields = ('product_name',)
child_models = [SmartPhoneModel, SmartCard, Commodity]
list_display = ['product_name', 'get_price', 'product_type', 'active']
list_display_links = ['product_name']
search_fields = ['product_name']
list_filter = (PolymorphicChildModelFilter, CMSPageFilter,)
list_per_page = 250
list_max_show_all = 1000
Expand Down

0 comments on commit cf7e46c

Please sign in to comment.