Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add bootstrap-django to admin
Marek Brzóskae02c950d07c2
diff --git a/product/admin.py b/product/admin.pyindex 525bc18266..d9131c359d 100644--- a/product/admin.py+++ b/product/admin.py@@ -1,6 +1,18 @@+from django.forms import ModelFormfrom django.contrib import adminfrom .models import Product, Category+from mptt.admin import MPTTModelAdmin+from saleor.utils import CategoryChoiceField-admin.site.register(Category)-admin.site.register(Product)+class ProductForm(ModelForm):+ class Meta:+ model = Product+ category = CategoryChoiceField(Category.objects.all())+++class ProductAdmin(admin.ModelAdmin):+ form = ProductForm++admin.site.register(Product, ProductAdmin)+admin.site.register(Category, MPTTModelAdmin)diff --git a/saleor/settings.py b/saleor/settings.pyindex cc2670a999..23b899245a 100644--- a/saleor/settings.py+++ b/saleor/settings.py@@ -50,7 +50,8 @@ TEMPLATE_DIRS = (TEMPLATE_LOADERS = ('django.template.loaders.filesystem.Loader','django.template.loaders.app_directories.Loader',- # 'django.template.loaders.eggs.Loader',+ # TODO: this one is slow, but for now need for mptt?+ 'django.template.loaders.eggs.Loader',)# Make this unique, and don't share it with anybody.@@ -67,6 +68,9 @@ MIDDLEWARE_CLASSES = ()INSTALLED_APPS = (+ # External apps that need to go before django's+ 'admin_bootstrap',+# Django modules'django.contrib.auth','django.contrib.contenttypes',@@ -75,8 +79,11 @@ INSTALLED_APPS = ('django.contrib.messages','django.contrib.staticfiles','django.contrib.admin',+# External apps'south',+ 'mptt',+# Local apps'product',)diff --git a/saleor/templates/admin/mptt_change_list_results.html b/saleor/templates/admin/mptt_change_list_results.htmlnew file mode 100644index 0000000000..e71889caf5--- /dev/null+++ b/saleor/templates/admin/mptt_change_list_results.html@@ -0,0 +1,26 @@+{% if result_hidden_fields %}+<div class="hiddenfields">{# DIV for HTML validation #}+{% for item in result_hidden_fields %}{{ item }}{% endfor %}+</div>+{% endif %}+{% if results %}+<div class="results">+<table cellspacing="0" id="result_list" class="table table-bordered table-striped">+<thead>+<tr>+{% for header in result_headers %}<th scope="col"{{ header.class_attrib }}>+{{ header.text|capfirst }}+{% if header.sortable %}</a>{% endif %}</th>{% endfor %}+</tr>+</thead>+<tbody>+{% for result in results %}+{% if result.form.non_field_errors %}+ <tr><td colspan="{{ result|length }}">{{ result.form.non_field_errors }}</td></tr>+{% endif %}+<tr class="{% cycle 'row1' 'row2' %}">{% for item in result %}{{ item }}{% endfor %}</tr>+{% endfor %}+</tbody>+</table>+</div>+{% endif %}diff --git a/saleor/utils.py b/saleor/utils.pynew file mode 100644index 0000000000..19c48396a3--- /dev/null+++ b/saleor/utils.py@@ -0,0 +1,17 @@+# coding: utf-8++from django import forms+++class CategoryChoiceField(forms.ModelChoiceField):+ def label_from_instance(self, obj):+ level = getattr(obj, obj._mptt_meta.level_attr)+ indent = max(0, level - 1) * u'│'+ if obj.parent:+ last = ((obj.parent.rght - obj.rght == 1)+ and (obj.rght - obj.lft == 1))+ if last:+ indent += u'└ '+ else:+ indent += u'├ '+ return u'%s%s' % (indent, unicode(obj))