parent
a12014e2f1
commit
e0d26e8a7a
4 changed files with 56 additions and 3 deletions
|
@ -1,5 +1,5 @@
|
|||
from django.contrib import admin
|
||||
from .models import Element, ElementDescription
|
||||
from .models import Element, ElementDescription, ElementSeparator
|
||||
|
||||
|
||||
class ElementDescriptionInline(admin.StackedInline):
|
||||
|
@ -12,3 +12,4 @@ class ElementAdmin(admin.ModelAdmin):
|
|||
|
||||
|
||||
admin.site.register(Element, ElementAdmin)
|
||||
admin.site.register(ElementSeparator)
|
||||
|
|
22
navbar/migrations/0002_elementseparator.py
Normal file
22
navbar/migrations/0002_elementseparator.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
# Generated by Django 2.0.1 on 2018-01-29 21:12
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('navbar', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='ElementSeparator',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('weight', models.PositiveSmallIntegerField()),
|
||||
('parent', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='navbar.Element')),
|
||||
],
|
||||
),
|
||||
]
|
|
@ -9,7 +9,8 @@ class Element(models.Model):
|
|||
'Element',
|
||||
on_delete=models.CASCADE,
|
||||
null=True,
|
||||
blank=True
|
||||
blank=True,
|
||||
limit_choices_to={'parent': None}
|
||||
)
|
||||
link = models.CharField(max_length=512, blank=True)
|
||||
new_window = models.BooleanField(default=False)
|
||||
|
@ -25,7 +26,14 @@ class Element(models.Model):
|
|||
return os.path.join('icons', os.path.basename(self.icon))
|
||||
|
||||
def children(self):
|
||||
return Element.objects.filter(parent=self.id).order_by('weight')
|
||||
return sorted(
|
||||
list(Element.objects.filter(parent=self.id).order_by('weight')) +
|
||||
list(
|
||||
ElementSeparator.objects.filter(parent=self.id)
|
||||
.order_by('weight')
|
||||
),
|
||||
key=lambda c: c.weight
|
||||
)
|
||||
|
||||
def description(self):
|
||||
return ElementDescription.objects.filter(
|
||||
|
@ -44,3 +52,21 @@ class ElementDescription(models.Model):
|
|||
short_name = models.CharField(max_length=32)
|
||||
full_name = models.CharField(max_length=64, blank=True)
|
||||
description = models.CharField(max_length=512, blank=True)
|
||||
|
||||
def is_separator(self):
|
||||
return False
|
||||
|
||||
|
||||
class ElementSeparator(models.Model):
|
||||
parent = models.ForeignKey(
|
||||
Element,
|
||||
on_delete=models.CASCADE,
|
||||
limit_choices_to={'parent': None}
|
||||
)
|
||||
weight = models.PositiveSmallIntegerField()
|
||||
|
||||
def is_separator(self):
|
||||
return True
|
||||
|
||||
def __str__(self):
|
||||
return '{} ({})'.format(self.parent, self.weight)
|
||||
|
|
|
@ -16,9 +16,13 @@
|
|||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
|
||||
{% for c in e.children %}
|
||||
{% if c.is_separator %}
|
||||
<hr />
|
||||
{% else %}
|
||||
<a class="dropdown-item" href="{{ c.link }}"{% if c.new_window %} target="_blank"{% endif %}{% if c.description.full_name or c.description.description %} data-toggle="tooltip" data-placement="right" data-html="true" title="{% if c.description.full_name %}<b>{{ c.description.full_name }}</b>{% endif %}{% if c.description.full_name and c.description.description %}<hr />{% endif %}{{ c.description.description }}"{% endif %}>
|
||||
<img src="{% static c.icon_path %}" alt="" /> {{ c }}
|
||||
</a>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</li>
|
||||
|
|
Loading…
Reference in a new issue