add KBitem.order to allow ordering items

This commit is contained in:
Petr Dlouhý 2020-02-25 14:43:10 +01:00
parent 5a594b7436
commit d0aafd6135
3 changed files with 30 additions and 2 deletions

View File

@ -70,7 +70,7 @@ class FollowUpAdmin(admin.ModelAdmin):
@admin.register(KBItem) @admin.register(KBItem)
class KBItemAdmin(admin.ModelAdmin): class KBItemAdmin(admin.ModelAdmin):
list_display = ('category', 'title', 'last_updated', 'team', ) list_display = ('category', 'title', 'last_updated', 'team', 'order')
inlines = [KBIAttachmentInline] inlines = [KBIAttachmentInline]
readonly_fields = ('voted_by', 'downvoted_by') readonly_fields = ('voted_by', 'downvoted_by')

View File

@ -0,0 +1,22 @@
# Generated by Django 2.2.10 on 2020-02-25 13:40
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('helpdesk', '0030_add_kbcategory_name'),
]
operations = [
migrations.AlterModelOptions(
name='kbitem',
options={'ordering': ('order', 'title'), 'verbose_name': 'Knowledge base item', 'verbose_name_plural': 'Knowledge base items'},
),
migrations.AddField(
model_name='kbitem',
name='order',
field=models.PositiveIntegerField(blank=True, null=True, verbose_name='Order'),
),
]

View File

@ -1317,6 +1317,12 @@ class KBItem(models.Model):
null=True, null=True,
) )
order = models.PositiveIntegerField(
_('Order'),
blank=True,
null=True,
)
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
if not self.last_updated: if not self.last_updated:
self.last_updated = timezone.now() self.last_updated = timezone.now()
@ -1333,7 +1339,7 @@ class KBItem(models.Model):
return '%s: %s' % (self.category.title, self.title) return '%s: %s' % (self.category.title, self.title)
class Meta: class Meta:
ordering = ('title',) ordering = ('order', 'title',)
verbose_name = _('Knowledge base item') verbose_name = _('Knowledge base item')
verbose_name_plural = _('Knowledge base items') verbose_name_plural = _('Knowledge base items')