gault-millau/apps/authorization/models.py

33 lines
914 B
Python

from django.db import models
from oauth2_provider import models as oauth2_models
from oauth2_provider.models import AbstractApplication
from utils.models import PlatformMixin
# Create your models here.
class ApplicationQuerySet(models.QuerySet):
"""Application queryset"""
def get_by_natural_key(self, client_id):
return self.get(client_id=client_id)
def by_source(self, source: int):
"""Filter by source parameter"""
return self.filter(source=source)
class ApplicationManager(oauth2_models.ApplicationManager):
"""Application manager"""
class Application(PlatformMixin, AbstractApplication):
"""Custom oauth2 application model"""
objects = ApplicationManager.from_queryset(ApplicationQuerySet)()
class Meta(AbstractApplication.Meta):
swappable = "OAUTH2_PROVIDER_APPLICATION_MODEL"
def natural_key(self):
return (self.client_id,)