Compare commits
4 Commits
7aecc21528
...
47bbec8dfe
Author | SHA1 | Date | |
---|---|---|---|
47bbec8dfe | |||
b690967d5d | |||
2dae592258 | |||
c1371cdd94 |
7
.gitignore
vendored
7
.gitignore
vendored
@ -1,5 +1,4 @@
|
|||||||
venv
|
venv/
|
||||||
.vscode
|
.vscode/
|
||||||
__pycache__
|
__pycache__/
|
||||||
db.sqlite3
|
db.sqlite3
|
||||||
website/db.sqlite3
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
# Register your models here.
|
from blog.models import *
|
||||||
|
|
||||||
|
admin.site.register(Post)
|
@ -1,6 +1,7 @@
|
|||||||
# Generated by Django 4.0 on 2022-01-07 23:05
|
# Generated by Django 4.0 on 2022-01-08 06:45
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
@ -8,6 +9,7 @@ class Migration(migrations.Migration):
|
|||||||
initial = True
|
initial = True
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
('auth', '0012_alter_user_first_name_max_length'),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
@ -15,10 +17,13 @@ class Migration(migrations.Migration):
|
|||||||
name='Post',
|
name='Post',
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
('title', models.CharField(max_length=200, unique=True)),
|
('created', models.DateTimeField(auto_now_add=True)),
|
||||||
('updated_on', models.DateTimeField(auto_now=True)),
|
('title', models.CharField(blank=True, default='', max_length=100)),
|
||||||
('created_on', models.DateTimeField(auto_now_add=True)),
|
('body', models.TextField(blank=True, default='')),
|
||||||
('content', models.TextField()),
|
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='posts', to='auth.user')),
|
||||||
],
|
],
|
||||||
|
options={
|
||||||
|
'ordering': ['created'],
|
||||||
|
},
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
@ -8,11 +8,11 @@ STATUS = (
|
|||||||
(1,"Publish")
|
(1,"Publish")
|
||||||
)
|
)
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
|
|
||||||
class Post(models.Model):
|
class Post(models.Model):
|
||||||
title = models.CharField(max_length=200, unique=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
# author = models.ForeignKey('user.auth',on_delete=models.CASCADE)
|
title = models.CharField(max_length=100, blank=True, default='')
|
||||||
updated_on =models.DateTimeField(auto_now= True)
|
body = models.TextField(blank=True, default='')
|
||||||
created_on = models.DateTimeField(auto_now_add=True)
|
owner = models.ForeignKey('auth.User', related_name='posts', on_delete=models.CASCADE)
|
||||||
content = models.TextField()
|
|
||||||
# status = models.IntegerChoices()
|
class Meta:
|
||||||
|
ordering = ['created']
|
Binary file not shown.
@ -1,3 +1,80 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
from django.contrib.admin.models import LogEntry, DELETION
|
||||||
|
|
||||||
# Register your models here.
|
from django.utils.html import escape
|
||||||
|
from django.utils.safestring import mark_safe
|
||||||
|
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from snippets.models import *
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#LogEntry
|
||||||
|
@admin.register(LogEntry)
|
||||||
|
class LogEntryAdmin(admin.ModelAdmin):
|
||||||
|
# to have a date-based drilldown navigation in the admin page
|
||||||
|
date_hierarchy = "action_time"
|
||||||
|
|
||||||
|
# to filter the resultes by users, content types and action flags
|
||||||
|
list_filter = ["user", "content_type", "action_flag"]
|
||||||
|
|
||||||
|
# when searching the user will be able to search in both object_repr and change_message
|
||||||
|
search_fields = ["object_repr", "change_message"]
|
||||||
|
|
||||||
|
list_display = [
|
||||||
|
"action_time",
|
||||||
|
"user",
|
||||||
|
"content_type",
|
||||||
|
"action_flag",
|
||||||
|
"object_link",
|
||||||
|
]
|
||||||
|
|
||||||
|
def has_add_permission(self, request):
|
||||||
|
return False
|
||||||
|
|
||||||
|
def has_change_permission(self, request, obj=None):
|
||||||
|
return False
|
||||||
|
|
||||||
|
def has_delete_permission(self, request, obj=None):
|
||||||
|
return False
|
||||||
|
|
||||||
|
def has_view_permission(self, request, obj=None):
|
||||||
|
return request.user.is_staff
|
||||||
|
|
||||||
|
def object_link(self, obj):
|
||||||
|
if obj.action_flag == DELETION:
|
||||||
|
link = escape(obj.object_repr)
|
||||||
|
else:
|
||||||
|
ct = obj.content_type
|
||||||
|
link = '<a href="%s">%s</a>' % (
|
||||||
|
reverse(
|
||||||
|
"admin:%s_%s_change" % (ct.app_label, ct.model),
|
||||||
|
args=[obj.object_id],
|
||||||
|
),
|
||||||
|
escape(obj.object_repr),
|
||||||
|
)
|
||||||
|
return mark_safe(link)
|
||||||
|
|
||||||
|
object_link.admin_order_field = "object_repr"
|
||||||
|
object_link.short_description = "object"
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(Snippet)
|
||||||
|
class SnippetAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
|
date_hierarchy = "created"
|
||||||
|
ordering= ['-created']
|
||||||
|
# add hyperlinked highlighted view and
|
||||||
|
# possibly code preview js magic
|
||||||
|
list_filter = ('owner', 'language', 'style')
|
||||||
|
list_display = ['id',
|
||||||
|
'title',
|
||||||
|
'owner',
|
||||||
|
'created',
|
||||||
|
'language']
|
||||||
|
search_fields = ['owner', 'title', 'language']
|
||||||
|
|
||||||
|
# @admin.register)
|
||||||
|
# class SnippetAdmin(admin.ModelAdmin):
|
||||||
|
# pass
|
@ -128,5 +128,9 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
|||||||
|
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
|
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
|
||||||
'PAGE_SIZE': 10
|
'PAGE_SIZE': 10,
|
||||||
|
'DEFAULT_AUTHENTICATION_CLASSES': [
|
||||||
|
'rest_framework.authentication.BasicAuthentication',
|
||||||
|
'rest_framework.authentication.SessionAuthentication',
|
||||||
|
]
|
||||||
}
|
}
|
Reference in New Issue
Block a user