Table Duplication issue

 avatar
user_2525525
django
a year ago
4.0 kB
2
Indexable
Never
## Master Tables Which is created only once

class LabTestDepartmentMaster(BaseModel):
    id = models.BigAutoField(primary_key=True)
    dept_name = models.CharField(max_length=50, blank=True, null=True,help_text='Lab Test Department Name')
    print_order = models.SmallIntegerField(null=True,blank=True,help_text="Test Result Order of Print Report")
    is_active = models.BooleanField(default=True)

    class Meta:
        db_table='lab_test_department_master'

class LabTestGroupMaster(BaseModel):
    id = models.BigAutoField(primary_key=True)
    grp_name = models.CharField(max_length=50, blank=True, null=True,help_text='Lab Test Group Name')
    print_order = models.SmallIntegerField(null=True,blank=True,help_text="Test Result Order of Print Report")
    is_active = models.BooleanField(default=True)

    class Meta:
        db_table='lab_test_group_master'

class LabTestMaster(BaseModel):
    id = models.BigAutoField(primary_key=True)
    dept = models.ForeignKey(LabTestDepartmentMaster, on_delete=models.CASCADE,help_text='Test Department')
    grp = models.ForeignKey(LabTestGroupMaster, on_delete=models.CASCADE,help_text='Test Group')
    test_name = models.CharField(max_length=100, blank=True, null=True,help_text='Lab Test Name')
    specimen = models.CharField(max_length=50, blank=True, null=True)
    method = models.CharField(max_length=50, blank=True, null=True)
    result_type = models.SmallIntegerField(choices=RESULT_TYPE,blank=True, null=True)
    test_data = models.JSONField(null=True,blank=True,help_text="Test Config Reference Data")
    print_order = models.SmallIntegerField(null=True,blank=True,help_text="Test Result Order of Print Report")
    is_active = models.BooleanField(default=True)

    class Meta:
        db_table='lab_test_master'

## Individual lab based data below
## here im making copy from master table above , only id,dept_name,grp_name,test_name are non editable 

class IndividualLabTestDepartmentMaster(BaseModel):
    lab = models.ForeignKey(LaboratoryDetails,on_delete=models.CASCADE)
    id = models.BigAutoField(primary_key=True)
    dept_name = models.CharField(max_length=50, blank=True, null=True,help_text='Lab Test Department Name')
    print_order = models.SmallIntegerField(null=True,blank=True,help_text="Test Result Order of Print Report")
    is_active = models.BooleanField(default=True)

    class Meta:
        db_table='lab_test_department_master'

class IndividualLabTestGroupMaster(BaseModel):
    lab = models.ForeignKey(LaboratoryDetails,on_delete=models.CASCADE)
    id = models.BigAutoField(primary_key=True)
    grp_name = models.CharField(max_length=50, blank=True, null=True,help_text='Lab Test Group Name')
    print_order = models.SmallIntegerField(null=True,blank=True,help_text="Test Result Order of Print Report")
    is_active = models.BooleanField(default=True)

    class Meta:
        db_table='lab_test_group_master'

class IndividualLabTestMaster(BaseModel):
    lab = models.ForeignKey(LaboratoryDetails,on_delete=models.CASCADE)
    id = models.BigAutoField(primary_key=True)
    dept = models.ForeignKey(LabTestDepartmentMaster, on_delete=models.CASCADE,help_text='Test Department')
    grp = models.ForeignKey(LabTestGroupMaster, on_delete=models.CASCADE,help_text='Test Group')
    test_name = models.CharField(max_length=100, blank=True, null=True,help_text='Lab Test Name')
    specimen = models.CharField(max_length=50, blank=True, null=True)
    method = models.CharField(max_length=50, blank=True, null=True)
    result_type = models.SmallIntegerField(choices=RESULT_TYPE,blank=True, null=True)
    test_data = models.JSONField(null=True,blank=True,help_text="Test Config Reference Data")
    print_order = models.SmallIntegerField(null=True,blank=True,help_text="Test Result Order of Print Report")
    is_active = models.BooleanField(default=True)

    class Meta:
        db_table='lab_test_master'