My project is about laboratory reporting system. I have three models TestCategory, Test and Report
class TestCategory(MPTTModel):
name = models.CharField(max_length=100)
parent = TreeForeignKey(‘self’, on_delete=models.CASCADE, null=True, blank=True, related_name=‘children’)
…
class Test(models.Model):
test_category = TreeForeignKey(TestCategory, on_delete=models.CASCADE, related_name=‘test_category’)
name = models.CharField(max_length=50)
…
class Report(models.Model):
patient_id = models.ForeignKey(‘Patient’, related_name=‘patients’, on_delete=models.CASCADE)
test_id = models.ManyToManyField(Test, verbose_name='Select Tests', related_name='tests')
I am using django-mptt, it works great in the sense to add category sub category from admin site but i am really having a hard to render the proper data in front end. I tried to follow mptt documentation but could only retrieve the category and sub category name for TestCategory model.
what i want is a form where user should be able to select the test they want to perform.
Example
* Bio Chemistry (Category name from TestCategory model)
- (input checkbox) Glucose, Random (Test Model that has Bio Chemistry as Parent category)
- (input checkbox) Glucose, Fasting (Test Model that has Bio Chemistry as Parent category)
* Parasitology (Category name from TestCategory model)
** Urine Test (parasitology sub category)
*** Physical Examination (urine test sub category)
- (input checkbox) Color (Test Model that has Physical Examination as Parent category)
*** Microscopic Examination
- -(input checkbox) RBC (Test Model that has Microscopic Examination as Parent category)
Similarly there can be Stool Test and they other sub categories inside stool like physical, chemical etc.
I have attached a screen shot of my app. This one is hard coded and very badly coded app. All the categories, subcategories are used for Text or Label purpose only so frontend was hard coded with fields. I developed this years ago using php and codeigniter and now rewriting the same app in django.
Also in other note, I don’t need to use mptt. I don’t need any features like moving nodes or something like that. What i am looking for is a multi level category and list the test items. I will love it keep it very simple. Categories and sub categories will only have a name field that will be used to group the tests that are associated.
Thanks in advance