Skip to content

Commit

Permalink
Added files for Prefix model
Browse files Browse the repository at this point in the history
Changes to be committed:
	new file:   prefix/__init__.py
	new file:   prefix/admin.py
	new file:   prefix/apis.py
	new file:   prefix/apps.py
	new file:   prefix/migrations/__init__.py
	new file:   prefix/models.py
	new file:   prefix/selectors.py
	new file:   prefix/services.py
	new file:   prefix/urls.py
  • Loading branch information
HadleyKing committed Mar 14, 2024
1 parent 4cde8dc commit 2c7366f
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 0 deletions.
Empty file added prefix/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions prefix/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Prefix Admin Pannel
"""

from django.contrib import admin
from prefix.models import Prefix

admin.site.register(Prefix)
Empty file added prefix/apis.py
Empty file.
Empty file added prefix/apps.py
Empty file.
Empty file added prefix/migrations/__init__.py
Empty file.
18 changes: 18 additions & 0 deletions prefix/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django.db import models
from django.contrib.auth.models import Group, User
from django.utils import timezone

class Prefix(models.Model):
"""
"""

prefix = models.CharField(primary_key=True, max_length=5)
certifying_key = models.TextField(blank=True, null=True)
created = models.DateTimeField(default=timezone.now, blank=True, null=True)
description = models.TextField(blank=True, null=True)
owner = models.ForeignKey(User, on_delete=models.CASCADE, to_field="username")
authorized_groups = models.ManyToManyField(Group, blank=True, related_name='authorized_prefix')

def __str__(self):
"""String for representing the BCO model (in Admin site etc.)."""
return f"{self.prefix}"
7 changes: 7 additions & 0 deletions prefix/selectors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@


def is_accessible_by(self, user):
"""If no authorized_groups are specified, it's accessible by everyone"""
if self.authorized_users.exists():
return self.authorized_users.filter(id=user.id).exists()
return True
Empty file added prefix/services.py
Empty file.
7 changes: 7 additions & 0 deletions prefix/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Prefix Admin Pannel
"""

from django.contrib import admin
from prefix.models import Prefix

admin.site.register(Prefix)

0 comments on commit 2c7366f

Please sign in to comment.