Source

fida / web / models.py

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
from django.db import models
from fida.thumbnails.field import *
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
from datetime import datetime

# Create your models here.

RELIGION_CHOICES = (
    ('Chr',_("Christian")),
    ('Mus',_("Muslim")),
    ('Hin',_("Hindu")),
    ('Bud',_("Buddhist")),
    ('Oth',_("Other")),
    ) 

HEALTH_CHOICES = (
    ('G',_("Good")),
    ('A',_("Average")),
    ('P',_("Poor")),
    )


    
CHARACTER_CHOICES = (
    ('Fr', _("Friendly")),
    ('Ta', _("Talkative")),
    ('Qu', _("Quiet")),
    ('Am', _("Ambitious")),
    )
    
GENDER_CHOICES = (
    ('M',_("Male")),
    ('F',_("Female")),
    )

VOUCHER_CHOICES = (
    ('RCPT',_("Receipt")), 
    ('PAYT',_("Payment")),
    )
    
FKEYS = [
        'Language',
        'Hobby',
        'Character',
        'Job',
        'Longtermdiagnosis',
        'Medicalremarks'
        ]
        
MODS = [
        'Sponsor',
        'Child',
        'Projectsponsorship',
        'Sponsorship']
 
class Language(models.Model):
    """
        languages in english and finnish
        """
    en = models.CharField(_("Language English"),max_length=100,unique=True)
    fi = models.CharField(_("Language Finnish"),max_length=100,blank=True,null=True)
    class Admin:
        list_display = ("en","fi")
        search_fields = ["en"]
    class Meta:
        verbose_name_plural = _("Languages")
        verbose_name = _("language")
    def __unicode__(self):
        return u"%s" %(self.en) 
        
class Schoolstandard(models.Model):
    """
        languages in english and finnish
        """
    en = models.CharField(_("School Standard English"),max_length=100,unique=True)
    fi = models.CharField(_("School Standard Finnish"),max_length=100,blank=True,null=True)
    class Admin:
        list_display = ("en","fi")
        search_fields = ["en"]
    class Meta:
        verbose_name_plural = _("School standards")
        verbose_name = _("school standard")
    def __unicode__(self):
        return u"%s" %(self.en)
        
class Doctor(models.Model):
    name = models.CharField(_("Name"),max_length=100,unique=True)
    class Admin:
        list_display = ("name",)
        search_fields = ["name"]
    class Meta:
        verbose_name_plural = _("Doctors")
        verbose_name = _("doctor")
        ordering = ["name"]
    def __unicode__(self):
        return u"%s" %(self.name) 

    
class Hobby(models.Model):
    en = models.CharField(_("Hobby English"),max_length=100,unique=True)
    fi = models.CharField(_("Hobby Finnish"),max_length=100,blank=True,null=True)
    class Admin:
        list_display = ("en","fi")
        search_fields = ["en"]
    class Meta:
        verbose_name_plural = _("Hobbies")
        verbose_name = _("hobby")
        ordering = ["en"]
    def __unicode__(self):
        return u"%s" %(self.en)

class Character(models.Model):
    en = models.CharField(_("Character English"),max_length=100,unique=True)
    fi = models.CharField(_("Character Finnish"),max_length=100,blank=True,null=True)
    class Admin:
        list_display = ("en","fi")
        search_fields = ["en"]
    class Meta:
        verbose_name_plural = _("Character types")
        verbose_name = _("character type")
        ordering = ["en"]
    def __unicode__(self):
        return u"%s" %(self.en)
        
class Job(models.Model):
    en = models.CharField(_("Job English"),max_length=100,unique=True)
    fi = models.CharField(_("Job Finnish"),max_length=100,blank=True,null=True)
    class Admin:
        list_display = ("en","fi")
        search_fields = ["en"]
    class Meta:
        verbose_name_plural = _("Jobs")
        verbose_name = _("job")
        ordering = ["en"]
    def __unicode__(self):
        return u"%s" %(self.en)
    
class Longtermdiagnosis(models.Model):
    en = models.CharField(_("Diagnosis English"),max_length=250,unique=True)
    fi = models.CharField(_("Diagnosis Finnish"),max_length=250,blank=True,null=True)
    class Admin:
        list_display = ("en","fi")
        search_fields = ["en"]
    class Meta:
        verbose_name_plural = _("Longtermdiagnosis")
        verbose_name = _("longtermdiagnosis")
        ordering = ["en"]
    def __unicode__(self):
        return u"%s" %(self.en)
    
class Medicalremarks(models.Model):
    en = models.CharField(_("Medical Remarks English"),max_length=250,unique=True)
    fi = models.CharField(_("Medical Remarks Finnish"),max_length=250,blank=True,null=True)
    class Admin:
        list_display = ("en","fi")
        search_fields = ["en"]
    class Meta:
        verbose_name_plural = _("Medical Remarks")
        verbose_name = _("medical remarks")
        ordering = ["en"]
    def __unicode__(self):
        return u"%s" %(self.en)
        
        
class Area(models.Model):
    code = models.IntegerField(_("Area Code Number"), unique=True)
    name = models.CharField(_("Area Name"),max_length=150,unique=True)
    description_en = models.TextField(_("Area Description in English"),blank=True,null=True)
    description_fi = models.TextField(_("Area Description in Finnish"),blank=True,null=True)
    picture = models.ImageField(_("Picture of Area"),upload_to="images/misc",
                                            blank=True,null=True)
    iscurrent = models.BooleanField(_("Is active"),default = True)
    class Admin:
        list_display = ("name","code",)
        search_fields = ["code"]
        js = ("js/tiny_mce/tiny_mce.js","js/tiny_mce/textareas.js")
    class Meta:
        verbose_name_plural = _("Areas")
        verbose_name = _("area")
    def __unicode__(self):
        return u"%s" %(self.name)
        
class Sponsor(models.Model):
    code = models.IntegerField(_("Sponsor Code Number"), unique=True)
    fname = models.CharField(_("First Name"),max_length=80,
                                                blank=True,null=True)
    lname = models.CharField(_("Last Name"),max_length=80)
    street = models.TextField(_("Street Address"),blank=True,null=True)
    city = models.TextField(_("City or Town"),blank=True,null=True)
    postal = models.TextField(_("Postal Code"),blank=True,null=True)
    country = models.CharField(_("Country"),max_length=100,blank=True,null=True)
    phone = models.CharField(_("Phone Numbers"),max_length=50,blank=True,null=True)
    email = models.EmailField(_("Email Address"),blank=True,null=True)
    remarks_eng = models.TextField(_("Remarks in English"),blank=True,null=True)
    remarks_fin = models.TextField(_("Remarks in Finnish"),blank=True,null=True)
    iscurrent = models.BooleanField(_("Is active"),default = True)
    isproject = models.BooleanField(_("Is Project Sponsor"),default = False)
    def Sponsor_Is_Active(self):
        return self.iscurrent
    class Admin:
        list_display = ("code","lname","fname","Sponsor_Is_Active")
        search_fields = ["code","lname"]
        list_filter = ('iscurrent',)
    class Meta:
        ordering = ['lname','fname']
        verbose_name_plural = _("Sponsors")
        verbose_name = _("sponsor")
    def __unicode__(self):
        return u'%s %s %s' %(self.code,self.lname,self.fname)
        

        
class Child(models.Model):
    code = models.IntegerField(_("Child Code Number"), unique=True)
    area = models.ForeignKey(Area,verbose_name=_("Area"))
    name = models.CharField(_("Child Name"),max_length=80)
    sex = models.CharField(_("Sex"),max_length=2,choices=GENDER_CHOICES)
    dob = models.DateField(_("Date of Birth"))
    language = models.ForeignKey(Language,verbose_name=_("Language"),
                                                        related_name='languages')
    religion = models.CharField(_("Religion"),max_length=3,choices=RELIGION_CHOICES)

    schoolstd = models.ForeignKey(Schoolstandard,verbose_name=_("School Standard"))
    character = models.ForeignKey(Character,verbose_name=_("Character"),
                                                        related_name='Character')
    schoolperf = models.CharField(_("School Performance"),max_length=3,choices=HEALTH_CHOICES)
    hobbies = models.ManyToManyField(Hobby,verbose_name=_("Hobbies"),
                                related_name='hobbies',filter_interface=models.HORIZONTAL,blank=True,null=True)
    fathername = models.CharField(_("Father Name"),max_length=80)
    fatherjob = models.ForeignKey(Job,verbose_name=_("Father Job"),
                                                        related_name='Fathers_Job')
    mothername = models.CharField(_("Mother Name"),max_length=80)
    motherjob = models.ForeignKey(Job,verbose_name=_("Mother Job"),
                                                        related_name='Mothers_Job')
    siblings = models.TextField(_("Siblings"),blank=True,null=True)
    remarks_eng = models.TextField(_("Remarks in English"),blank=True,null=True)
    remarks_fin = models.TextField(_("Remarks in Finnish"),blank=True,null=True)
    picture = models.ImageField(_("Picture of Child"),
            upload_to="images/misc",blank=True,null=True)
    iscurrent = models.BooleanField(_("Is active"),default = True)
    class Admin:
        list_display = ("code","name","fatherjob","motherjob","character",
                    "Child_Is_Active")
        search_fields = ["code","name"]
        list_filter = ('iscurrent',)
    def Child_Is_Active(self):
        return self.iscurrent
    class Meta:
        verbose_name_plural = _("Children")
        verbose_name = _("child")
        ordering = ["code"]
    def __unicode__(self):
        return u"%s: %s" %(self.code,self.name)
    
class Sponsorship(models.Model):
    """ links child to sponsor, startdate enddate and comments"""
    sponsor = models.ForeignKey(Sponsor,verbose_name=_("Sponsor"),
       limit_choices_to={'isproject':False})
    child = models.ForeignKey(Child,verbose_name=_("Child"))
    startdate = models.DateField(_("Start Date"))
    enddatedate = models.DateField(_("End Date"),blank=True,null=True)
    remarks_eng = models.TextField(_("Remarks in English"),blank=True,null=True)
    remarks_fin = models.TextField(_("Remarks in Finnish"),blank=True,null=True)
    iscurrent = models.BooleanField(_("Is active"),default = True)
    def Sponsorship_Is_Active(self):
        return self.iscurrent
    class Admin:
        list_display = ("sponsor","child","Sponsorship_Is_Active")
        search_fields = ["sponsor__code","child__code"]
        list_filter = ('iscurrent',)
        js = ("js/tiny_mce/tiny_mce.js","js/tiny_mce/textareassmall.js")
    class Meta:
        verbose_name_plural = _("Sponsorships")
        verbose_name = _("sponsorship")
    def __unicode__(self):
        return u"%s: %s" %(self.sponsor,self.child)
        
class Projectsponsorship(models.Model):
    """ links child to sponsor, startdate enddate and comments"""
    sponsor = models.ForeignKey(Sponsor,verbose_name=_("Sponsor"),
       limit_choices_to={'isproject':True})
    area = models.ForeignKey(Area,verbose_name=_("Area"))
    startdate = models.DateField(_("Start Date"))
    enddatedate = models.DateField(_("End Date"),blank=True,null=True)
    children = models.IntegerField(_("Number of children"),blank=True,null=True)
    remarks_eng = models.TextField(_("Remarks in English"),blank=True,null=True)
    remarks_fin = models.TextField(_("Remarks in Finnish"),blank=True,null=True)
    class Admin:
        list_display = ("sponsor","area",)
        search_fields = ["sponsor","area"]
        js = ("js/tiny_mce/tiny_mce.js","js/tiny_mce/textareassmall.js")
    class Meta:
        verbose_name_plural = _("Project Sponsorships")
        verbose_name = _("project sponshorship")
    def __unicode__(self):
        return u"%s: %s" %(self.sponsor,self.area)
        
class Checkup(models.Model):
    """ Doctors checkup report"""
    child = models.ForeignKey(Child,verbose_name=_("Child"))
    chkdate = models.DateField(_("Date"))
    height = models.IntegerField(_("Height in cms"),blank=True,null=True)
    weight = models.DecimalField(_("Weight in kgs"),max_digits=5,decimal_places=2,
                                                    blank=True,null=True)
    ltdiag = models.ManyToManyField(Longtermdiagnosis,verbose_name=_("Longterm Diagnosis"),
                filter_interface=models.HORIZONTAL,blank=True,null=True)
    medrem = models.ManyToManyField(Medicalremarks,verbose_name=_("Medical Remarks"),
                filter_interface=models.HORIZONTAL,blank=True,null=True)
    health = models.CharField(_("Health"),max_length=2,choices=HEALTH_CHOICES)
    doctor = models.ForeignKey(Doctor,verbose_name=_("Doctor"))
    def Child_Is_Active(self):
        return self.child.iscurrent
    class Meta:
        ordering = ['child']
        unique_together = (("child","chkdate"),)
        verbose_name_plural = _("Checkups")
        verbose_name = _("checkup")
    class Admin:
        list_display = ("child","chkdate","Child_Is_Active")
        search_fields = ["child__code","chkdate"]
    def __unicode__(self):
        return u"%s: %s" %(self.child,self.chkdate)
        
class Childnote(models.Model):
    child = models.ForeignKey(Child,verbose_name=_("Child"))
    notedate = models.DateField(_("Date"),default=datetime.now)
    matter_en = models.TextField(_("Note in English"),blank=True,null=True)
    matter_fn = models.TextField(_("Note in Finnish"),blank=True,null=True)
    class Admin:
        list_display = ("notedate","child",)
        search_fields = ["notedate","child"]
    class Meta:
        verbose_name_plural = _("Notes on child")
        verbose_name = _("note on child")
    def __unicode__(self):
        return u"%s: %s" %(self.notedate,self.child)
        
class Sponsornote(models.Model):
    sponsor = models.ForeignKey(Sponsor,verbose_name=_("Sponsor"))
    notedate = models.DateField(_("Date"),default=datetime.now)
    matter_en = models.TextField(_("Note in English"),blank=True,null=True)
    matter_fn = models.TextField(_("Note in Finnish"),blank=True,null=True)
    class Admin:
        list_display = ("notedate","sponsor",)
        search_fields = ["notedate","sponsor"]
#        js = ("js/tiny_mce/tiny_mce.js","js/tiny_mce/textareassmall.js")
    class Meta:
        verbose_name_plural = _("Notes on sponsor")
        verbose_name = _("note on sponsor")
    def __unicode__(self):
        return u"%s: %s" %(self.date,self.sponsor)
        
class Areanote(models.Model):
    area = models.ForeignKey(Area,verbose_name=_("Area"))
    notedate = models.DateField(_("Date"),default=datetime.now)
    matter_en = models.TextField(_("Note in English"),blank=True,null=True)
    matter_fn = models.TextField(_("Note in Finnish"),blank=True,null=True)
    class Admin:
        list_display = ("notedate","area",)
        search_fields = ["notedate","area"]
#        js = ("js/tiny_mce/tiny_mce.js","js/tiny_mce/textareassmall.js")
    class Meta:
        verbose_name_plural = _("Notes on area")
        verbose_name = _("note on area")
    def __unicode__(self):
        return u"%s: %s" %(self.notedate,self.area)
        
class Download(models.Model):
    name = models.CharField(_("Name of Document"),max_length=250,unique=True)
    document = models.FileField(_("File"),upload_to="images/downloads/")
    class Admin:
        list_display = ("name",)
        search_fields = ["name"]
       
    class Meta:
        verbose_name_plural = _("Downloads")
        verbose_name = _("download")
    def __unicode__(self):
        return "%s" %(self.name)
    
""" Single entry financial accounting. Account head - code, name, type. Persons
    and vouchers - date, sno, head, person, amount, comments. Keep it simple
    """

class Accounthead(models.Model):
    """
        heads of account - caters for both code and codelesss
        """
    name = models.CharField(_("Name of account"),max_length=100)
    code = models.IntegerField(_("Code"))
    payment = models.CharField(_("Receipt or Payment"),max_length=5,choices=VOUCHER_CHOICES)

    class Meta:
        unique_together = (("name","code"),)
        verbose_name_plural = _("Heads of Account")
    def __unicode__(self):
        return u"%d %s" %(self.code,self.name) 
        
class Costcenter(models.Model):
    """
        who pays or receives money
        """
    name = models.CharField(_("Name of cost center"),max_length=200,unique=True)

    class Meta:
        verbose_name_plural = _("Cost Centers")
        ordering = ["name"]
    def __unicode__(self):
        return u"%s" %(self.name) 
        
class Voucher(models.Model):
    """
        single entry as this is a not for profit - why not double entry?
        """
    sno = models.CharField(_("Unique serial number"),max_length=15,unique=True)
    head = models.ForeignKey(Accounthead, verbose_name=_("Name of account"))
    costcenter = models.ForeignKey(Costcenter,verbose_name=_("Cost Center"))
    accdate = models.DateField(_("Date"),default=datetime.now)
    amount = models.DecimalField(_("Amount"),max_digits=13,decimal_places=2)
    person = models.ForeignKey(User, verbose_name=_("Entered By"),editable=False)
    comments = models.TextField(_("Comments"))
    class Meta:
        ordering = (("accdate"),)
        verbose_name_plural = _("Vouchers")
    def __unicode__(self):
        return u"%s %s %s %s %s" %(self.sno,self.head,self.amount,self.date,self.costcenter) 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.