forked from wiktor/spejstore-new
Make add another default, add select2, remember last parent
This commit is contained in:
parent
b653ec8e25
commit
8b539e5926
|
@ -1,4 +1,6 @@
|
||||||
Django==1.10.1
|
Django==1.10.1
|
||||||
git+https://github.com/djangonauts/django-hstore@61427e474cb2f4be8fdfce225d78a5330bc77eb0#egg=django-hstore
|
git+https://github.com/djangonauts/django-hstore@61427e474cb2f4be8fdfce225d78a5330bc77eb0#egg=django-hstore
|
||||||
|
django-appconf==1.0.2
|
||||||
|
Django-Select2==5.8.10
|
||||||
Pillow==3.3.1
|
Pillow==3.3.1
|
||||||
psycopg2==2.6.2
|
psycopg2==2.6.2
|
||||||
|
|
|
@ -41,6 +41,7 @@ INSTALLED_APPS = [
|
||||||
|
|
||||||
'django_hstore',
|
'django_hstore',
|
||||||
'tree',
|
'tree',
|
||||||
|
'django_select2',
|
||||||
|
|
||||||
'storage',
|
'storage',
|
||||||
]
|
]
|
||||||
|
|
|
@ -11,6 +11,7 @@ from django.conf.urls.static import static
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^admin/', admin.site.urls),
|
url(r'^admin/', admin.site.urls),
|
||||||
|
url(r'^select2/', include('django_select2.urls')),
|
||||||
|
|
||||||
url(r'^', include('storage.urls')),
|
url(r'^', include('storage.urls')),
|
||||||
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from .models import Item, ItemImage, Category
|
from .models import Item, ItemImage, Category
|
||||||
|
from django_select2.forms import Select2Widget, Select2MultipleWidget
|
||||||
|
|
||||||
|
|
||||||
class ItemForm(forms.ModelForm):
|
class ItemForm(forms.ModelForm):
|
||||||
name = forms.CharField(widget=forms.TextInput())
|
name = forms.CharField(widget=forms.TextInput())
|
||||||
|
@ -8,6 +10,10 @@ class ItemForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Item
|
model = Item
|
||||||
exclude = []
|
exclude = []
|
||||||
|
widgets = {
|
||||||
|
'parent': Select2Widget,
|
||||||
|
'categories': Select2MultipleWidget
|
||||||
|
}
|
||||||
|
|
||||||
class ItemImageInline(admin.TabularInline):
|
class ItemImageInline(admin.TabularInline):
|
||||||
model = ItemImage
|
model = ItemImage
|
||||||
|
@ -22,6 +28,27 @@ class ItemAdmin(admin.ModelAdmin):
|
||||||
def _name(self, obj):
|
def _name(self, obj):
|
||||||
return '-' * obj.get_level() + '> ' + obj.name
|
return '-' * obj.get_level() + '> ' + obj.name
|
||||||
|
|
||||||
|
def save_model(self, request, obj, form, change):
|
||||||
|
super(ItemAdmin, self).save_model(request, obj, form, change)
|
||||||
|
|
||||||
|
# Store last input parent to use as default on next creation
|
||||||
|
if obj.parent:
|
||||||
|
request.session['last-parent'] = str(obj.parent.uuid)
|
||||||
|
else:
|
||||||
|
request.session['last-parent'] = str(obj.uuid)
|
||||||
|
|
||||||
|
def get_changeform_initial_data(self, request):
|
||||||
|
data = {
|
||||||
|
'parent': request.session.get('last-parent')
|
||||||
|
}
|
||||||
|
data.update(super(ItemAdmin, self).get_changeform_initial_data(request))
|
||||||
|
return data
|
||||||
|
|
||||||
|
class Media:
|
||||||
|
js = (
|
||||||
|
# Required by select2
|
||||||
|
'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js',
|
||||||
|
)
|
||||||
|
|
||||||
admin.site.register(Item, ItemAdmin)
|
admin.site.register(Item, ItemAdmin)
|
||||||
admin.site.register(Category)
|
admin.site.register(Category)
|
||||||
|
|
|
@ -27,11 +27,12 @@ class Category(models.Model):
|
||||||
|
|
||||||
class Item(models.Model, TreeModelMixin):
|
class Item(models.Model, TreeModelMixin):
|
||||||
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||||
name = models.TextField()
|
|
||||||
|
|
||||||
parent = models.ForeignKey('self', null=True, blank=True)
|
parent = models.ForeignKey('self', null=True, blank=True)
|
||||||
path = PathField()
|
path = PathField()
|
||||||
|
|
||||||
|
name = models.TextField()
|
||||||
|
|
||||||
description = models.TextField(blank=True, null=True)
|
description = models.TextField(blank=True, null=True)
|
||||||
state = models.CharField(max_length=31, choices=STATES, default=STATES[0][0])
|
state = models.CharField(max_length=31, choices=STATES, default=STATES[0][0])
|
||||||
categories = models.ManyToManyField(Category, blank=True)
|
categories = models.ManyToManyField(Category, blank=True)
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
{% extends "admin/change_form.html" %}
|
||||||
|
|
||||||
|
{% block submit_buttons_bottom %}
|
||||||
|
{# We want add another to be default submit action #}
|
||||||
|
<input type="submit" value="Save" class="hidden" name="_addanother" />
|
||||||
|
{{ block.super }}
|
||||||
|
{% endblock %}
|
|
@ -15,7 +15,8 @@ def apply_smart_search(query, objects):
|
||||||
key, value = prop.split(':', 1)
|
key, value = prop.split(':', 1)
|
||||||
if hasattr(Item, key):
|
if hasattr(Item, key):
|
||||||
filters[key + '__search'] = value
|
filters[key + '__search'] = value
|
||||||
|
elif key == 'ancestor':
|
||||||
|
objects = Item.objects.get(pk=value).get_children()
|
||||||
elif key == 'prop' or value:
|
elif key == 'prop' or value:
|
||||||
if key == 'prop':
|
if key == 'prop':
|
||||||
key, value = value.split(':', 1)
|
key, value = value.split(':', 1)
|
||||||
|
|
|
@ -7,31 +7,41 @@
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||||
<link rel="stylesheet" href="{% static 'css/bootstrap.css' %}" media="screen">
|
<link rel="stylesheet" href="{% static 'css/bootstrap.css' %}" media="screen">
|
||||||
<style>
|
|
||||||
.btn {
|
|
||||||
font-size: 1.4em;
|
|
||||||
text-transform: none;
|
|
||||||
margin-bottom: 10px;
|
|
||||||
padding: 15px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn .glyphicon {
|
|
||||||
padding: 0 10px;
|
|
||||||
}
|
|
||||||
.btn-alt {
|
|
||||||
background: #4b176d;
|
|
||||||
color:white;
|
|
||||||
border-color: #2d0d42; /*#301934;*/
|
|
||||||
}
|
|
||||||
.btn-alt:hover, .btn-alt:active, .btn-alt:link, .btn-alt:visited {
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
{% block body %}
|
{% block body %}
|
||||||
|
<nav class="navbar navbar-default">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h1 class="page-header">Warsaw Hackerspace <small class="hidden-sm hidden-xs">Enjoy your stay</small></h1>
|
<div class="navbar-header">
|
||||||
|
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
|
||||||
|
<span class="sr-only">Toggle navigation</span>
|
||||||
|
<span class="icon-bar"></span>
|
||||||
|
<span class="icon-bar"></span>
|
||||||
|
<span class="icon-bar"></span>
|
||||||
|
</button>
|
||||||
|
<a class="navbar-brand" href="/">spejstore</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
|
||||||
|
<ul class="nav navbar-nav">
|
||||||
|
<li><a href="/item/">Items</a></li>
|
||||||
|
</ul>
|
||||||
|
<form class="navbar-form navbar-right" role="search" action="/search">
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="input-group">
|
||||||
|
<input type="text" class="form-control" placeholder="Search" name="q">
|
||||||
|
<span class="input-group-btn">
|
||||||
|
<button class="btn btn-primary" type="submit"><i class="glyphicon glyphicon-search"></i></button>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
<div class="container">
|
||||||
|
<!--<h1 class="page-header">Warsaw Hackerspace <small class="hidden-sm
|
||||||
|
hidden-xs">Enjoy your stay</small></h1>-->
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue