Compare commits

..

No commits in common. "47bbec8dfe9d5a2edf39ef916a5bc281718dd77f" and "7aecc21528e1383f1655b1eff0cf563010f9e84c" have entirely different histories.

7 changed files with 19 additions and 106 deletions

7
.gitignore vendored
View File

@ -1,4 +1,5 @@
venv/
.vscode/
__pycache__/
venv
.vscode
__pycache__
db.sqlite3
website/db.sqlite3

View File

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

View File

@ -1,7 +1,6 @@
# Generated by Django 4.0 on 2022-01-08 06:45
# Generated by Django 4.0 on 2022-01-07 23:05
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
@ -9,7 +8,6 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
('auth', '0012_alter_user_first_name_max_length'),
]
operations = [
@ -17,13 +15,10 @@ class Migration(migrations.Migration):
name='Post',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created', models.DateTimeField(auto_now_add=True)),
('title', models.CharField(blank=True, default='', max_length=100)),
('body', models.TextField(blank=True, default='')),
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='posts', to='auth.user')),
('title', models.CharField(max_length=200, unique=True)),
('updated_on', models.DateTimeField(auto_now=True)),
('created_on', models.DateTimeField(auto_now_add=True)),
('content', models.TextField()),
],
options={
'ordering': ['created'],
},
),
]

View File

@ -8,11 +8,11 @@ STATUS = (
(1,"Publish")
)
# Create your models here.
class Post(models.Model):
created = models.DateTimeField(auto_now_add=True)
title = models.CharField(max_length=100, blank=True, default='')
body = models.TextField(blank=True, default='')
owner = models.ForeignKey('auth.User', related_name='posts', on_delete=models.CASCADE)
class Meta:
ordering = ['created']
class Post(models.Model):
title = models.CharField(max_length=200, unique=True)
# author = models.ForeignKey('user.auth',on_delete=models.CASCADE)
updated_on =models.DateTimeField(auto_now= True)
created_on = models.DateTimeField(auto_now_add=True)
content = models.TextField()
# status = models.IntegerChoices()

Binary file not shown.

View File

@ -1,80 +1,3 @@
from django.contrib import admin
from django.contrib.admin.models import LogEntry, DELETION
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
# Register your models here.

View File

@ -128,9 +128,5 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 10,
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
]
'PAGE_SIZE': 10
}