fix(MR-16): Use cache for FileField and ImageField (#17)
* Remove casting to list in _get_form_data * Use cache for most fields and admin form for m2m files * MR comments/clean up * Cache should obey exclude and fields * Some more tests and docs * Only use cache for image files * Even more tests and handle save as new * fix test * More tests * minor refactor * Improve test coverage * Add no cover for some places * V0.2.3.dev7 * Adding tests for fieldsets * Added cache timeout * Added another test for an edge case * Fix issue with ManagementForm tampered with * Update cache to only set when form is_multipart * Even more testing changes * Update based on comments on MR and clean up a bit * make test names better Co-authored-by: Thu Trang Pham <thu@joinmodernhealth.com>
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from ..models import GeneralManager, Item, Inventory, Shop, ShoppingMall
|
||||
|
||||
from .item_admin import ItemAdmin
|
||||
from .inventory_admin import InventoryAdmin
|
||||
from .shop_admin import ShopAdmin
|
||||
from .shoppingmall_admin import ShoppingMallAdmin
|
||||
from .generalmanager_admin import GeneralManagerAdmin
|
||||
|
||||
admin.site.register(Item, ItemAdmin)
|
||||
admin.site.register(Inventory, InventoryAdmin)
|
||||
admin.site.register(Shop, ShopAdmin)
|
||||
admin.site.register(ShoppingMall, ShoppingMallAdmin)
|
||||
admin.site.register(GeneralManager, GeneralManagerAdmin)
|
||||
@@ -0,0 +1,5 @@
|
||||
from django.contrib.admin import ModelAdmin
|
||||
|
||||
|
||||
class GeneralManagerAdmin(ModelAdmin):
|
||||
save_as = True
|
||||
@@ -0,0 +1,10 @@
|
||||
from django.contrib.admin import ModelAdmin
|
||||
from admin_confirm.admin import AdminConfirmMixin
|
||||
|
||||
|
||||
class InventoryAdmin(AdminConfirmMixin, ModelAdmin):
|
||||
list_display = ("shop", "item", "quantity")
|
||||
|
||||
confirm_change = True
|
||||
confirm_add = True
|
||||
confirmation_fields = ["quantity"]
|
||||
@@ -0,0 +1,28 @@
|
||||
from django.contrib.admin import ModelAdmin
|
||||
from django.utils.safestring import mark_safe
|
||||
from admin_confirm.admin import AdminConfirmMixin
|
||||
|
||||
|
||||
class ItemAdmin(AdminConfirmMixin, ModelAdmin):
|
||||
confirm_change = True
|
||||
confirm_add = True
|
||||
confirmation_fields = ["price"]
|
||||
|
||||
list_display = ("name", "price", "currency")
|
||||
readonly_fields = ["image_preview"]
|
||||
|
||||
save_as = True
|
||||
save_as_continue = False
|
||||
|
||||
def image_preview(self, obj):
|
||||
if obj.image:
|
||||
return mark_safe('<img src="{obj.image.url}" />')
|
||||
|
||||
# def one(self, obj):
|
||||
# return "Read Only"
|
||||
|
||||
# def two(self, obj):
|
||||
# return "Read Only"
|
||||
|
||||
# def three(self, obj):
|
||||
# return "Read Only"
|
||||
@@ -0,0 +1,21 @@
|
||||
from django.contrib.admin import ModelAdmin
|
||||
from admin_confirm.admin import AdminConfirmMixin, confirm_action
|
||||
|
||||
|
||||
class ShopAdmin(AdminConfirmMixin, ModelAdmin):
|
||||
confirmation_fields = ["name"]
|
||||
actions = ["show_message", "show_message_no_confirmation"]
|
||||
|
||||
@confirm_action
|
||||
def show_message(modeladmin, request, queryset):
|
||||
shops = ", ".join(shop.name for shop in queryset)
|
||||
modeladmin.message_user(request, f"You selected with confirmation: {shops}")
|
||||
|
||||
show_message.allowed_permissions = ("delete",)
|
||||
|
||||
def show_message_no_confirmation(modeladmin, request, queryset):
|
||||
shops = ", ".join(shop.name for shop in queryset)
|
||||
modeladmin.message_user(request, f"You selected without confirmation: {shops}")
|
||||
|
||||
def has_delete_permission(self, request, obj=None):
|
||||
return request.user.is_superuser
|
||||
@@ -0,0 +1,16 @@
|
||||
from ..models import ShoppingMall
|
||||
from django.contrib.admin import ModelAdmin
|
||||
from django.contrib.admin.options import StackedInline
|
||||
from admin_confirm.admin import AdminConfirmMixin
|
||||
|
||||
|
||||
class ShopInline(StackedInline):
|
||||
model = ShoppingMall.shops.through
|
||||
|
||||
|
||||
class ShoppingMallAdmin(AdminConfirmMixin, ModelAdmin):
|
||||
confirm_add = True
|
||||
confirm_change = True
|
||||
confirmation_fields = ["name"]
|
||||
|
||||
inlines = [ShopInline]
|
||||
Reference in New Issue
Block a user