bookwyrm/fedireads/models/base_model.py

25 lines
751 B
Python
Raw Normal View History

2020-03-07 06:56:44 +00:00
''' base model with default fields '''
from django.db import models
from fedireads.settings import DOMAIN
class FedireadsModel(models.Model):
2020-03-28 02:52:05 +00:00
''' fields and functions for every model '''
created_date = models.DateTimeField(auto_now_add=True)
updated_date = models.DateTimeField(auto_now=True)
@property
def absolute_id(self):
''' constructs the absolute reference to any db object '''
2020-05-10 20:38:47 +00:00
if self.remote_id:
return self.remote_id
base_path = 'https://%s' % DOMAIN
if hasattr(self, 'user'):
base_path = self.user.absolute_id
2020-02-18 01:53:40 +00:00
model_name = type(self).__name__.lower()
return '%s/%s/%d' % (base_path, model_name, self.id)
class Meta:
abstract = True