forked from openedx/openedx-authz
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
32 lines (25 loc) · 1020 Bytes
/
models.py
File metadata and controls
32 lines (25 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""
Database models for openedx_authz.
"""
from django.db import models
class Library(models.Model):
"""
Model representing an OpenedX Library with basic information.
"""
id = models.CharField(max_length=255, primary_key=True, help_text="Library ID in format lib:ORG:SLUG")
org = models.CharField(max_length=255, help_text="Organization name")
slug = models.CharField(max_length=255, help_text="Library slug/identifier")
title = models.CharField(max_length=255, help_text="Library title")
description = models.TextField(blank=True, help_text="Library description")
def save(self, *args, **kwargs):
"""
Override save method to automatically generate ID from org and slug.
"""
self.id = f"lib:{self.org}:{self.slug}".replace(" ", "_")
super().save(*args, **kwargs)
class Meta:
verbose_name = "Library"
verbose_name_plural = "Libraries"
ordering = ["title"]
def __str__(self):
return str(self.title)