Adding basic django admin sight.
[Evergreen.git] / Open-ILS / admin / ils_admin / setup / models.py
1 from django.db import models
2
3 # Create your models here.
4
5 class GrpTree(models.Model):
6         name = models.CharField(maxlength=100)
7         parent_id = models.ForeignKey('self', null=True, related_name='children', db_column='parent')
8         description = models.CharField(blank=True, maxlength=200)
9         perm_interval = models.CharField(blank=True, maxlength=100)
10         application_perm = models.CharField(blank=True, maxlength=100)
11         usergroup = models.BooleanField()
12         class Admin:
13                 list_display = ('name', 'description')
14                 list_filter = ['parent_id']
15                 search_fields = ['name', 'description']
16         class Meta:
17                 db_table = 'grp_tree'
18                 ordering = ['name']
19                 verbose_name = 'User Group'
20         def __str__(self):
21                 return self.name
22
23 class OrgUnitType(models.Model):
24         name = models.CharField(maxlength=100)
25         opac_label = models.CharField(maxlength=100)
26         depth = models.IntegerField()
27         parent_id = models.ForeignKey('self', null=True, related_name='children', db_column='parent')
28         can_have_vols = models.BooleanField()
29         can_have_users = models.BooleanField()
30         class Meta:
31                 db_table = 'org_unit_type'
32                 verbose_name = 'Library Type'
33         class Admin:
34                 list_display = ('name', 'depth')
35                 list_filter = ['parent_id']
36                 ordering = ['depth']
37         def __str__(self):
38                 return self.name
39
40 class PermList(models.Model):
41         code = models.CharField(maxlength=100)
42         description = models.CharField(blank=True, maxlength=200)
43         class Admin:
44                 list_display = ('code','description')
45                 search_fields = ['code']
46         class Meta:
47                 db_table = 'perm_list'
48                 ordering = ['code']
49                 verbose_name = 'Permission'
50         def __str__(self):
51                 return self.code
52
53 class GrpPermMap(models.Model):
54         grp_id = models.ForeignKey(GrpTree, db_column='grp')
55         perm_id = models.ForeignKey(PermList, db_column='perm')
56         depth_id = models.ForeignKey(OrgUnitType, to_field='depth', db_column='depth')
57         grantable = models.BooleanField()
58         class Admin:
59                 list_filter = ['grp_id']
60                 search_fields = ['grp_id', 'perm_id']
61                 list_display = ('grp_id', 'perm_id')
62         class Meta:
63                 db_table = 'grp_perm_map'
64                 ordering = ['grp_id']
65                 verbose_name = 'Permission Setting'
66         def __str__(self):
67                 return str(self.grp_id)+' -> '+str(self.perm_id)
68
69
70 class OrgAddress(models.Model):
71         valid = models.BooleanField()
72         org_unit_id = models.ForeignKey('OrgUnit', db_column='org_unit')
73         address_type = models.CharField(blank=False, maxlength=200, default='MAILING')
74         street1 = models.CharField(blank=False, maxlength=200)
75         street2 = models.CharField(maxlength=200)
76         city = models.CharField(blank=False, maxlength=200)
77         county = models.CharField(maxlength=200)
78         state = models.CharField(blank=False, maxlength=200)
79         country = models.CharField(blank=False, maxlength=200)
80         post_code = models.CharField(blank=False, maxlength=200)
81         class Admin:
82                 search_fields = ['street1', 'city', 'post_code']        
83                 list_filter = ['org_unit_id']
84                 list_display = ('street1', 'street2', 'city', 'county', 'state', 'post_code')
85         class Meta:
86                 ordering = ['city']
87                 db_table = 'org_address'
88                 verbose_name = 'Library Address'
89         def __str__(self):
90                 return self.street1+' '+self.city+', '+self.state+' '+self.post_code
91
92 class OrgUnit(models.Model):
93         parent_ou_id = models.ForeignKey('self', null=True, related_name='children', db_column='parent_ou')
94         ou_type_id = models.ForeignKey(OrgUnitType, db_column='ou_type')
95         shortname = models.CharField(maxlength=200)
96         name = models.CharField(maxlength=200)
97         email = models.EmailField(null=True, blank=True)
98         phone = models.CharField(maxlength=200, null=True, blank=True)
99         ill_address_id = models.ForeignKey(OrgAddress, db_column='ill_address', null=True, blank=True)
100         holds_address_id = models.ForeignKey(OrgAddress, db_column='holds_address', null=True, blank=True)
101         mailing_address_id = models.ForeignKey(OrgAddress, db_column='mailing_address', null=True, blank=True)
102         billing_address_id = models.ForeignKey(OrgAddress, db_column='billing_address', null=True, blank=True)
103         class Admin:
104                 search_fields = ['name', 'shortname']
105                 #list_filter = ['parent_ou_id']
106                 list_display = ('shortname', 'name')
107         class Meta:
108                 db_table = 'org_unit'
109                 ordering = ['shortname']
110                 verbose_name = 'Library'
111         def __str__(self):
112                 return self.shortname
113
114
115
116