Add Member table from membershipworks database
This commit is contained in:
parent
090bb9e07a
commit
16eb034b03
@ -62,7 +62,7 @@ TEMPLATES = [
|
||||
WSGI_APPLICATION = 'member_paperwork.wsgi.application'
|
||||
|
||||
|
||||
DATABASE_ROUTERS = ['paperwork.routers.PaperworkRouter']
|
||||
DATABASE_ROUTERS = ['paperwork.routers.MembershipWorksRouter', 'paperwork.routers.PaperworkRouter']
|
||||
|
||||
|
||||
# Password validation
|
||||
|
@ -1,7 +1,9 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from .models import (CmsRedRiverVeteransScholarship, CertificationDefinition,
|
||||
Certification, InstructorOrVendor, SpecialProgram, Waiver)
|
||||
from .models import (CmsRedRiverVeteransScholarship,
|
||||
CertificationDefinition, Certification,
|
||||
InstructorOrVendor, SpecialProgram, Waiver,
|
||||
Member)
|
||||
|
||||
|
||||
class CertificationDefinitionAdmin(admin.ModelAdmin):
|
||||
@ -24,9 +26,20 @@ 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,6 +1,22 @@
|
||||
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'
|
||||
|
||||
|
||||
class CmsRedRiverVeteransScholarship(models.Model):
|
||||
serial = models.AutoField(primary_key=True)
|
||||
program_name = models.CharField(db_column='Program Name', max_length=255)
|
||||
@ -38,7 +54,8 @@ class Certification(models.Model):
|
||||
number = models.AutoField(db_column='Number', primary_key=True)
|
||||
certification = models.ForeignKey(CertificationDefinition, on_delete=models.PROTECT, db_column='Certification')
|
||||
name = models.CharField(db_column='Name', max_length=255)
|
||||
uid = models.CharField(max_length=24, blank=True, null=True)
|
||||
# TODO: this should be a fk to the membershipworks.members table
|
||||
member = models.ForeignKey(Member, on_delete=models.PROTECT, to_field='uid', db_column='uid', blank=True, null=True)
|
||||
certified_by = models.CharField(db_column='Certified_By', max_length=255, blank=True, null=True)
|
||||
date = models.DateField(db_column='Date', blank=True, null=True)
|
||||
version = models.CharField(db_column='Version', max_length=255, blank=True, null=True)
|
||||
|
@ -1,3 +1,6 @@
|
||||
from .models import Member
|
||||
|
||||
|
||||
class PaperworkRouter:
|
||||
app_label = 'paperwork'
|
||||
db = 'cms'
|
||||
@ -12,6 +15,32 @@ class PaperworkRouter:
|
||||
return self.db
|
||||
return None
|
||||
|
||||
def allow_relation(self, obj1, obj2, **hints):
|
||||
if (obj1 == Member and obj2._meta.app_label == self.app_label) or \
|
||||
(obj2 == Member and obj1._meta.app_label == self.app_label):
|
||||
return True
|
||||
return None
|
||||
|
||||
def allow_migrate(self, db, app_label, model_name=None, **hints):
|
||||
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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user