Skip to content

Commit

Permalink
add order for bookmark links
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongnb14 committed Oct 22, 2021
1 parent ff557fd commit c21cfa7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
4 changes: 2 additions & 2 deletions admin_reskin/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

@admin.register(models.Bookmark)
class BookmarkAdmin(admin.ModelAdmin):
list_display = ('name', 'url', 'is_active')
list_display = ('name', 'url', 'is_active', 'order')
list_filter = ('is_active',)
list_editable = ('is_active',)
list_editable = ('is_active', 'order')

def get_urls(self):
urls = super().get_urls()
Expand Down
18 changes: 18 additions & 0 deletions admin_reskin/migrations/0002_bookmark_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2 on 2021-10-22 03:02

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('admin_reskin', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='bookmark',
name='order',
field=models.PositiveSmallIntegerField(default=0),
),
]
1 change: 1 addition & 0 deletions admin_reskin/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Bookmark(models.Model):
name = models.CharField(max_length=45)
url = models.CharField(max_length=1000)
is_active = models.BooleanField(default=True)
order = models.PositiveSmallIntegerField(default=0)

def __str__(self):
return self.name
2 changes: 1 addition & 1 deletion admin_reskin/templatetags/sort_menu_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def sort_apps(apps):
else max_index
)

bookmarks = Bookmark.objects.filter(is_active=True)
bookmarks = Bookmark.objects.filter(is_active=True).order_by('order')
bookmarks_model = []
for bookmark in bookmarks:
item = {
Expand Down

0 comments on commit c21cfa7

Please sign in to comment.