mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2026-04-02 22:07:58 +10:00
first working django model with archivebox-shell command and sql exporting
This commit is contained in:
@@ -0,0 +1 @@
|
||||
__package__ = 'archivebox.core'
|
||||
|
||||
28
archivebox/core/migrations/0001_initial.py
Normal file
28
archivebox/core/migrations/0001_initial.py
Normal file
@@ -0,0 +1,28 @@
|
||||
# Generated by Django 2.2 on 2019-04-17 06:46
|
||||
|
||||
from django.db import migrations, models
|
||||
import uuid
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Page',
|
||||
fields=[
|
||||
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
||||
('url', models.URLField()),
|
||||
('timestamp', models.CharField(default=None, max_length=32, null=True)),
|
||||
('title', models.CharField(default=None, max_length=128, null=True)),
|
||||
('tags', models.CharField(default=None, max_length=256, null=True)),
|
||||
('added', models.DateTimeField(auto_now_add=True)),
|
||||
('bookmarked', models.DateTimeField()),
|
||||
('updated', models.DateTimeField(default=None, null=True)),
|
||||
],
|
||||
),
|
||||
]
|
||||
27
archivebox/core/migrations/0002_auto_20190417_0739.py
Normal file
27
archivebox/core/migrations/0002_auto_20190417_0739.py
Normal file
@@ -0,0 +1,27 @@
|
||||
# Generated by Django 2.2 on 2019-04-17 07:39
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('core', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='page',
|
||||
name='bookmarked',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='page',
|
||||
name='timestamp',
|
||||
field=models.CharField(default=None, max_length=32, null=True, unique=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='page',
|
||||
name='url',
|
||||
field=models.URLField(unique=True),
|
||||
),
|
||||
]
|
||||
@@ -1,3 +1,33 @@
|
||||
__package__ = 'archivebox.core'
|
||||
|
||||
import uuid
|
||||
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
|
||||
class Page(models.Model):
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
|
||||
url = models.URLField(unique=True)
|
||||
timestamp = models.CharField(unique=True, max_length=32, null=True, default=None)
|
||||
|
||||
title = models.CharField(max_length=128, null=True, default=None)
|
||||
tags = models.CharField(max_length=256, null=True, default=None)
|
||||
|
||||
added = models.DateTimeField(auto_now_add=True)
|
||||
updated = models.DateTimeField(null=True, default=None)
|
||||
# bookmarked = models.DateTimeField()
|
||||
|
||||
sql_args = ('url', 'timestamp', 'title', 'tags', 'updated')
|
||||
|
||||
@classmethod
|
||||
def from_json(cls, info: dict):
|
||||
info = {k: v for k, v in info.items() if k in cls.sql_args}
|
||||
return cls(**info)
|
||||
|
||||
def as_json(self, *args) -> dict:
|
||||
args = args or self.sql_args
|
||||
return {
|
||||
key: getattr(self, key)
|
||||
for key in args
|
||||
}
|
||||
|
||||
@@ -1,24 +1,22 @@
|
||||
__package__ = 'archivebox.core'
|
||||
|
||||
from ..legacy.config import (
|
||||
TEMPLATES_DIR,
|
||||
DATABASE_FILE,
|
||||
)
|
||||
|
||||
import os
|
||||
|
||||
SECRET_KEY = '---------------- not a valid secret key ! ----------------'
|
||||
DEBUG = True
|
||||
|
||||
|
||||
INSTALLED_APPS = [
|
||||
# 'django.contrib.admin',
|
||||
# 'django.contrib.auth',
|
||||
# 'django.contrib.contenttypes',
|
||||
# 'django.contrib.sessions',
|
||||
# 'django.contrib.messages',
|
||||
# 'django.contrib.staticfiles',
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
|
||||
'core',
|
||||
|
||||
'django_extensions',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
@@ -35,7 +33,7 @@ ROOT_URLCONF = 'core.urls'
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [TEMPLATES_DIR],
|
||||
'DIRS': ['templates'],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
@@ -53,7 +51,7 @@ WSGI_APPLICATION = 'core.wsgi.application'
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': DATABASE_FILE,
|
||||
'NAME': os.path.join(os.path.abspath(os.curdir), 'database', 'database.sqlite3'),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user