Create database models
Create models for storing data in the database.
In this section
Creating the database models
from django.db import models
class Work(models.Model):
frbr_uri = models.CharField(max_length=512, unique=True)
title = models.CharField(max_length=512)
metadata = models.JSONField()
class Meta:
ordering = ['title']
def __str__(self):
return f'{self.title} ({self.frbr_uri})'
class Expression(models.Model):
# the expression inherits most of its metadata from its work
work = models.ForeignKey(Work, related_name='expressions', on_delete=models.PROTECT)
# the expression's FRBR URI is more specific than its work's
frbr_uri = models.CharField(max_length=512, unique=True)
# the expression's title may differ from its work's
title = models.CharField(max_length=512)
# the expression has a language, date, and content, which its work doesn't have
language_code = models.CharField(max_length=3)
date = models.DateField()
content = models.TextField(null=True, blank=True)
toc_json = models.JSONField()
class Meta:
# latest first
ordering = ['-date']
def __str__(self):
return f'{self.title} ({self.frbr_uri})'
Last updated