feat(ISSUE-8): fixing error caused by ManyToManyField on confirmation (#9)
* feat(ISSUE-8): ISSUE-8: ManyToManyField causes error on confirmations * feat(ISSUE-8): Update some readme and remove print statements Co-authored-by: Thu Trang Pham <thu@joinmodernhealth.com>
This commit is contained in:
+10
-3
@@ -2,7 +2,7 @@ from django.contrib import admin
|
||||
|
||||
from admin_confirm.admin import AdminConfirmMixin, confirm_action
|
||||
|
||||
from .models import Item, Inventory, Shop
|
||||
from .models import Item, Inventory, Shop, ShoppingMall
|
||||
|
||||
|
||||
class ItemAdmin(AdminConfirmMixin, admin.ModelAdmin):
|
||||
@@ -19,7 +19,6 @@ class InventoryAdmin(AdminConfirmMixin, admin.ModelAdmin):
|
||||
|
||||
class ShopAdmin(AdminConfirmMixin, admin.ModelAdmin):
|
||||
confirmation_fields = ["name"]
|
||||
|
||||
actions = ["show_message", "show_message_no_confirmation"]
|
||||
|
||||
@confirm_action
|
||||
@@ -27,7 +26,7 @@ class ShopAdmin(AdminConfirmMixin, admin.ModelAdmin):
|
||||
shops = ", ".join(shop.name for shop in queryset)
|
||||
modeladmin.message_user(request, f"You selected with confirmation: {shops}")
|
||||
|
||||
show_message.allowed_permissions = ('delete',)
|
||||
show_message.allowed_permissions = ("delete",)
|
||||
|
||||
def show_message_no_confirmation(modeladmin, request, queryset):
|
||||
shops = ", ".join(shop.name for shop in queryset)
|
||||
@@ -36,6 +35,14 @@ class ShopAdmin(AdminConfirmMixin, admin.ModelAdmin):
|
||||
def has_delete_permission(self, request, obj=None):
|
||||
return request.user.is_superuser
|
||||
|
||||
|
||||
class ShoppingMallAdmin(AdminConfirmMixin, admin.ModelAdmin):
|
||||
confirm_add = True
|
||||
confirm_change = True
|
||||
confirmation_fields = ["name"]
|
||||
|
||||
|
||||
admin.site.register(Item, ItemAdmin)
|
||||
admin.site.register(Inventory, InventoryAdmin)
|
||||
admin.site.register(Shop, ShopAdmin)
|
||||
admin.site.register(ShoppingMall, ShoppingMallAdmin)
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
# Generated by Django 3.1.6 on 2021-02-18 17:46
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('market', '0004_inventory_notes'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='ShoppingMall',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=120)),
|
||||
('shops', models.ManyToManyField(to='market.Shop')),
|
||||
],
|
||||
),
|
||||
]
|
||||
@@ -33,3 +33,11 @@ class Inventory(models.Model):
|
||||
item = models.ForeignKey(to=Item, on_delete=models.CASCADE)
|
||||
quantity = models.PositiveIntegerField(default=0, null=True, blank=True)
|
||||
notes = models.TextField(default="This is the default", null=True, blank=True)
|
||||
|
||||
|
||||
class ShoppingMall(models.Model):
|
||||
name = models.CharField(max_length=120)
|
||||
shops = models.ManyToManyField(Shop)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
Reference in New Issue
Block a user