Add list view and admin for bookmarks
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
# Register your models here.
|
from . import models
|
||||||
|
|
||||||
|
admin.site.register(models.Bookmark)
|
||||||
|
|||||||
@@ -2,4 +2,7 @@ from django.db import models
|
|||||||
|
|
||||||
class Bookmark(models.Model):
|
class Bookmark(models.Model):
|
||||||
title = models.CharField(max_length=255,null=True)
|
title = models.CharField(max_length=255,null=True)
|
||||||
url = models.URLField(max_length=2048)
|
url = models.URLField(max_length=2048)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.title
|
||||||
8
bookmarks/templates/bookmarks/bookmark_list.html
Normal file
8
bookmarks/templates/bookmarks/bookmark_list.html
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<h1>Bookmarks</h1>
|
||||||
|
<ul>
|
||||||
|
{% for bookmark in object_list %}
|
||||||
|
<li>{{ bookmark.title }} - {{ bookmark.url }}</li>
|
||||||
|
{% empty %}
|
||||||
|
<li>No bookmarks yet.</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
7
bookmarks/urls.py
Normal file
7
bookmarks/urls.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
from . import views
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path('', views.BookmarkListView.as_view(), name='bookmark-list')
|
||||||
|
]
|
||||||
@@ -1,3 +1,13 @@
|
|||||||
from django.shortcuts import render
|
from django.utils import timezone
|
||||||
|
from django.views.generic.list import ListView
|
||||||
|
|
||||||
# Create your views here.
|
from .models import Bookmark
|
||||||
|
|
||||||
|
class BookmarkListView(ListView):
|
||||||
|
model = Bookmark
|
||||||
|
paginate_by = 20
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
|
context['now'] = timezone.now()
|
||||||
|
return context
|
||||||
|
|||||||
@@ -14,8 +14,9 @@ Including another URLconf
|
|||||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
"""
|
"""
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path
|
from django.urls import include, path
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
path('bookmarks/', include('bookmarks.urls')),
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user