My application stores information about clinical trial and patients. We have a
model for the patient which has the usual fields, such as name, date of birth,
etc. One of the fields is patient_id, which is optional and is used by some of
our clients but not others. As such, the ModelForm will validate if this is
left blank.
I have a requirement from a new client that the patient_id field be required.
The easiest thing to do would be to add a boolean field to the Study model the
patient is related to. In fact, I have done this already with the social
security number, but I think SSN is important enough to justify the field. I
don't want to keep adding arbitrary fields, especially when they may only be
used by one client.
My co-developer and I have discussed adding a text field to the Study model in
which we'll store serialized JSON, then create a property() with the getter and
setter functions to return value by key. So if we call
instance.extra_params('patient_id_required') we'd get back the value. One
potential issue I have with that is that, for a Study instance which doesn't
have the value already, I'd want the correct default value to be returned. In
addition, what if we want to implement this solution for other models besides
Study? That would be code duplication.
So I'm trying to think of a clever way to have some kind of config model, with
a generic foreign key, which stores arbitrary settings for model instances and
the defaults for that model type.
Do any of you know of an existing elegant solution to this kind of problem? Am
I being hard-headed by not just adding fields, considering the fact that I have
South and it's easy to add them and set sane defaults? Something in my lizard
brain just tells me that's a bad idea.
Thanks,
Shawn
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
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.