Move Members model to new "membershipworks" app
This commit is contained in:
parent
192145e32a
commit
4fb8aa74f0
@ -28,6 +28,7 @@ INSTALLED_APPS = [
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'membershipworks.apps.MembershipworksConfig',
|
||||
'paperwork.apps.PaperworkConfig',
|
||||
]
|
||||
|
||||
@ -62,7 +63,8 @@ TEMPLATES = [
|
||||
WSGI_APPLICATION = 'member_paperwork.wsgi.application'
|
||||
|
||||
|
||||
DATABASE_ROUTERS = ['paperwork.routers.MembershipWorksRouter', 'paperwork.routers.PaperworkRouter']
|
||||
DATABASE_ROUTERS = ['membershipworks.routers.MembershipWorksRouter',
|
||||
'paperwork.routers.PaperworkRouter']
|
||||
|
||||
|
||||
# Internationalization
|
||||
|
0
membershipworks/__init__.py
Normal file
0
membershipworks/__init__.py
Normal file
14
membershipworks/admin.py
Normal file
14
membershipworks/admin.py
Normal file
@ -0,0 +1,14 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from .models import Member
|
||||
|
||||
|
||||
@admin.register(Member)
|
||||
class MemberAdmin(admin.ModelAdmin):
|
||||
readonly_fields = [field.name for field in Member._meta.get_fields() if field.concrete]
|
||||
|
||||
def has_add_permission(self, request, obj=None):
|
||||
return False
|
||||
|
||||
def has_delete_permission(self, request, obj=None):
|
||||
return False
|
6
membershipworks/apps.py
Normal file
6
membershipworks/apps.py
Normal file
@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class MembershipworksConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'membershipworks'
|
18
membershipworks/models.py
Normal file
18
membershipworks/models.py
Normal file
@ -0,0 +1,18 @@
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Member(models.Model):
|
||||
# TODO: this is only a partial set of fields, may want to expand
|
||||
uid = models.CharField(primary_key=True, max_length=24)
|
||||
year_of_birth = models.TextField(db_column='Year of Birth', blank=True, null=True)
|
||||
account_name = models.TextField(db_column='Account Name', blank=True, null=True)
|
||||
first_name = models.TextField(db_column='First Name', blank=True, null=True)
|
||||
last_name = models.TextField(db_column='Last Name', blank=True, null=True)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.account_name}"
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = 'members'
|
||||
ordering = ('first_name', 'last_name')
|
21
membershipworks/routers.py
Normal file
21
membershipworks/routers.py
Normal file
@ -0,0 +1,21 @@
|
||||
class MembershipWorksRouter:
|
||||
app_label = 'membershipworks'
|
||||
db = 'membershipworks'
|
||||
|
||||
def db_for_read(self, model, **hints):
|
||||
if model._meta.app_label == self.app_label:
|
||||
return self.db
|
||||
return None
|
||||
|
||||
def db_for_write(self, model, **hints):
|
||||
if model._meta.app_label == self.app_label:
|
||||
return self.db
|
||||
return None
|
||||
|
||||
def allow_relation(self, obj1, obj2, **hints):
|
||||
return None
|
||||
|
||||
def allow_migrate(self, db, app_label, model_name=None, **hints):
|
||||
if db == self.db:
|
||||
return False
|
||||
return None
|
3
membershipworks/tests.py
Normal file
3
membershipworks/tests.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
3
membershipworks/views.py
Normal file
3
membershipworks/views.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
@ -2,44 +2,33 @@ from django.contrib import admin
|
||||
|
||||
from .models import (CmsRedRiverVeteransScholarship,
|
||||
CertificationDefinition, Certification,
|
||||
InstructorOrVendor, SpecialProgram, Waiver,
|
||||
Member)
|
||||
InstructorOrVendor, SpecialProgram, Waiver)
|
||||
|
||||
|
||||
@admin.register(CertificationDefinition)
|
||||
class CertificationDefinitionAdmin(admin.ModelAdmin):
|
||||
search_fields = ['certification_name', 'department']
|
||||
|
||||
|
||||
@admin.register(Certification)
|
||||
class CertificationAdmin(admin.ModelAdmin):
|
||||
search_fields = ['name', 'certification__certification_name', 'certification__department']
|
||||
|
||||
|
||||
@admin.register(InstructorOrVendor)
|
||||
class InstructorOrVendorAdmin(admin.ModelAdmin):
|
||||
search_fields = ['name']
|
||||
|
||||
|
||||
@admin.register(SpecialProgram)
|
||||
class SpecialProgramAdmin(admin.ModelAdmin):
|
||||
search_fields = ['program_name']
|
||||
|
||||
|
||||
@admin.register(Waiver)
|
||||
class WaiverAdmin(admin.ModelAdmin):
|
||||
search_fields = ['name']
|
||||
|
||||
|
||||
class MemberAdmin(admin.ModelAdmin):
|
||||
readonly_fields = [field.name for field in Member._meta.get_fields() if field.concrete]
|
||||
|
||||
def has_add_permission(self, request, obj=None):
|
||||
return False
|
||||
|
||||
def has_delete_permission(self, request, obj=None):
|
||||
return False
|
||||
|
||||
|
||||
admin.site.register(CmsRedRiverVeteransScholarship)
|
||||
admin.site.register(CertificationDefinition, CertificationDefinitionAdmin)
|
||||
admin.site.register(Certification, CertificationAdmin)
|
||||
admin.site.register(InstructorOrVendor, InstructorOrVendorAdmin)
|
||||
admin.site.register(SpecialProgram, SpecialProgramAdmin)
|
||||
admin.site.register(Waiver, WaiverAdmin)
|
||||
admin.site.register(Member, MemberAdmin)
|
||||
|
||||
|
@ -1,21 +1,6 @@
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Member(models.Model):
|
||||
# TODO: this is only a partial set of fields, may want to expand
|
||||
uid = models.CharField(primary_key=True, max_length=24)
|
||||
year_of_birth = models.TextField(db_column='Year of Birth', blank=True, null=True)
|
||||
account_name = models.TextField(db_column='Account Name', blank=True, null=True)
|
||||
first_name = models.TextField(db_column='First Name', blank=True, null=True)
|
||||
last_name = models.TextField(db_column='Last Name', blank=True, null=True)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.account_name}"
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = 'members'
|
||||
ordering = ('first_name', 'last_name')
|
||||
from membershipworks.models import Member
|
||||
|
||||
|
||||
class CmsRedRiverVeteransScholarship(models.Model):
|
||||
|
@ -1,8 +1,6 @@
|
||||
from .models import Member
|
||||
|
||||
|
||||
class PaperworkRouter:
|
||||
app_label = 'paperwork'
|
||||
related_app_labels = {'paperwork', 'membershipworks'}
|
||||
db = 'cms'
|
||||
|
||||
def db_for_read(self, model, **hints):
|
||||
@ -16,8 +14,8 @@ class PaperworkRouter:
|
||||
return None
|
||||
|
||||
def allow_relation(self, obj1, obj2, **hints):
|
||||
if (isinstance(obj1, Member) and obj2._meta.app_label == self.app_label) or \
|
||||
(isinstance(obj2, Member) and obj1._meta.app_label == self.app_label):
|
||||
if obj1._meta.app_label in self.related_app_labels or \
|
||||
obj2._meta.app_label in self.related_app_labels:
|
||||
return True
|
||||
return None
|
||||
|
||||
@ -25,26 +23,3 @@ class PaperworkRouter:
|
||||
if db == self.db:
|
||||
return False
|
||||
return None
|
||||
|
||||
|
||||
# TODO: this is pretty hacky/special cased
|
||||
class MembershipWorksRouter:
|
||||
db = 'membershipworks'
|
||||
|
||||
def db_for_read(self, model, **hints):
|
||||
if model == Member:
|
||||
return self.db
|
||||
return None
|
||||
|
||||
def db_for_write(self, model, **hints):
|
||||
if model == Member:
|
||||
return self.db
|
||||
return None
|
||||
|
||||
def allow_relation(self, obj1, obj2, **hints):
|
||||
return None
|
||||
|
||||
def allow_migrate(self, db, app_label, model_name=None, **hints):
|
||||
if db == self.db:
|
||||
return False
|
||||
return None
|
||||
|
Loading…
Reference in New Issue
Block a user