From 3e434077f91517f1162bffa3eb195b31a52a1738 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 17 Feb 2020 16:50:44 -0800 Subject: [PATCH] Forgot to add the migration and models helper --- .../migrations/0002_auto_20200217_0309.py | 75 +++++++++++++++++++ fedireads/utils/models.py | 21 ++++++ 2 files changed, 96 insertions(+) create mode 100644 fedireads/migrations/0002_auto_20200217_0309.py create mode 100644 fedireads/utils/models.py diff --git a/fedireads/migrations/0002_auto_20200217_0309.py b/fedireads/migrations/0002_auto_20200217_0309.py new file mode 100644 index 000000000..1c05a22a2 --- /dev/null +++ b/fedireads/migrations/0002_auto_20200217_0309.py @@ -0,0 +1,75 @@ +# Generated by Django 3.0.3 on 2020-02-17 03:09 + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('fedireads', '0001_initial'), + ] + + operations = [ + migrations.RenameField( + model_name='author', + old_name='added_date', + new_name='created_date', + ), + migrations.RenameField( + model_name='book', + old_name='added_date', + new_name='created_date', + ), + migrations.RemoveField( + model_name='author', + name='updated_date', + ), + migrations.RemoveField( + model_name='book', + name='updated_date', + ), + migrations.RemoveField( + model_name='shelf', + name='updated_date', + ), + migrations.RemoveField( + model_name='user', + name='created_date', + ), + migrations.RemoveField( + model_name='user', + name='updated_date', + ), + migrations.AddField( + model_name='author', + name='content', + field=models.TextField(blank=True, null=True), + ), + migrations.AddField( + model_name='book', + name='content', + field=models.TextField(blank=True, null=True), + ), + migrations.AddField( + model_name='federatedserver', + name='content', + field=models.TextField(blank=True, null=True), + ), + migrations.AddField( + model_name='federatedserver', + name='created_date', + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), + preserve_default=False, + ), + migrations.AddField( + model_name='shelf', + name='content', + field=models.TextField(blank=True, null=True), + ), + migrations.AddField( + model_name='shelfbook', + name='content', + field=models.TextField(blank=True, null=True), + ), + ] diff --git a/fedireads/utils/models.py b/fedireads/utils/models.py new file mode 100644 index 000000000..5b80c02cf --- /dev/null +++ b/fedireads/utils/models.py @@ -0,0 +1,21 @@ +from django.db import models + +from fedireads.settings import DOMAIN + + +class FedireadsModel(models.Model): + content = models.TextField(blank=True, null=True) + created_date = models.DateTimeField(auto_now_add=True) + + @property + def absolute_id(self): + ''' constructs the absolute reference to any db object ''' + base_path = 'https://%s' % DOMAIN + if self.user: + base_path = self.user.absolute_id + model_name = type(self).__name__ + return '%s/%s/%d' % (base_path, model_name, self.id) + + class Meta: + abstract = True +