I think the most natural fit for this is a database like the google appengine provides, not a relational one: Attach a review to an encounter whenever needed, and access it as an attribute of the encounter
On Aug 19, 11:29 pm, omat <[EMAIL PROTECTED]> wrote: > Another approach can be to generate the Review model dynamically as > explained here:http://code.djangoproject.com/wiki/DynamicModels > > This way, the Review model can be generated dynamically based on the > Encounter model: For every field in the model create 3 for the Review. > > So, changes to the encounter model will be reflected to the Review > model resulting in DRYness. But this will not avoid the redundancy in > the db tables. > > Thanks... > > On Aug 19, 11:02 pm, omat <[EMAIL PROTECTED]> wrote: > > > Hi all, > > > I have a model class that holds patients' encounters. It has fields > > that hold some facts such as the date the record created, the doctor > > who diagnosed, etc. > > > Also there are about 20 other fields about the diagnosis. This data > > about the diagnosis are reviewed by experts. If an expert thinks an > > attribute of the diagnosis is wrong, he challenges that attribute and > > supplies the corrected value, his comments and the type of mistake he > > thinks exists. This is possible for all those 20 fields. > > > The corrected value is of the same type as the type of the challenged > > fields, therefore varies. Comments are TextField. Type of mistake is > > ManyToManyField. > > > The current model structure is as follows: > > > class Encounter(models.Model): > > # not challenged fields > > doctor = ... > > created = ... > > # challenged fields > > diagnosis = ForeignKey(...) > > patient_number = CharField > > operation1 = ForeignKey > > operation2 = ForeignKey > > activity = ForeignKey > > ... > > > and a Review model to hold the reviews: > > > class Review(models.Model > > encounter = ForeignKey(Encounter) > > diagnosis = ForeignKey(..., blank=True) > > diagnosis_comment = TextField() > > diagnosis_type = ManyToManyField(ChallengeType) > > patient_no = ForeignKey(..., blank=True) > > patient_no_comment = TextField() > > patient_no_type = ManyToManyField(ChallengeType) > > operation1 = ForeignKey(..., blank=True) > > operation1_comment = TextField() > > operation1_type = ManyToManyField(ChallengeType) > > # ... this goes on for every challengeable field ... > > > As can be seen, this not DRY at all, very error prone and introduces a > > lot of redundancy. > > > I can think of some alternatives such as keeping the field name as a > > reference to the field. This would reduce the Review models to > > something like this: > > > class Review(models.Model) > > encounter = ForeignKey(Encounter) > > field_name = CharField() > > new_value = CharField() > > comment = TextField() > > type = ManyToManyField(ChallengeType) > > > Two drawbacks of this approach I can think of are: > > - you cannot directly access the referenced field by the convenient db > > api way (or can you?) > > - the new_value cannot be of the same type as the challenged fields > > type, as we do not know which field it would refer to > > > Another approach I can think of is XML approach. The Review model can > > be as follows: > > > class Review(models.Model): > > encounter = ForeignKey(Encounter) > > review = XMLField() > > > And the 'review' XML field will hold all the data on reviewed fields > > in a non-relational and flexible format. > > > I cannot decide among these approaches as neither of them feels > > natural. > > > Any advice would be much appreciated. > > > thanks, > > omat --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---