Add list view and admin for bookmarks

This commit is contained in:
2021-03-10 08:58:23 -06:00
parent 80a1048533
commit c9d0d81972
6 changed files with 36 additions and 5 deletions

View File

@@ -1,3 +1,5 @@
from django.contrib import admin
# Register your models here.
from . import models
admin.site.register(models.Bookmark)

View File

@@ -2,4 +2,7 @@ from django.db import models
class Bookmark(models.Model):
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

View 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
View File

@@ -0,0 +1,7 @@
from django.urls import path
from . import views
urlpatterns = [
path('', views.BookmarkListView.as_view(), name='bookmark-list')
]

View File

@@ -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