Hi,

I have a sinking feeling that I'm missing something obvious here, so I
guess it's worth asking the list :) I'm using magic-removal, and...

I have a model which defines a time range, using a from_date and to_date
DateTimeField.

Only one record may exist in the database for any one point in time.
Restated, records may not have overlapping timespans. The problem with a
simple validator is that I have no way (that I know of) of getting the id of
the object being changed (on an update), and so if an overlap in the db is
detected, I don't know if that is the current object (it is OK for the item
to overlap with itself, because it will soon be updated), or another object.

At the moment I'm using a Manipulator inner class (I discovered that you
could do this by reading Django source, can't find any docs about it, maybe
I don't know where to look?). This inner class overrides the
get_validation_errors method, and looks like this:

class Manipulator:
  def get_validation_errors(self, new_data):
    id = None
    if hasattr(self, 'original_object'):
      id = self.original_object.id
    errors = forms.Manipulator.get_validation_errors(self, new_data)
    try:
      noOverlap( 
        new_data['from_date_date']+' '+new_data['from_date_time'],
        new_data['to_date_date']+' '+new_data['to_date_time'],
        id)
    except (validators.ValidationError,
            validators.CriticalValidationError), e:
      errors.setdefault('from_date_date', []).extend(e.messages)
    return errors

This is convenient -- I don't repeat myself, I get all the data I need to
successfully perform my validation (current object's ID, etc), and it works
with generic views :) (because it overrides the get_validation_errors in
AddManipulator and ChangeManipulator)

My question: Is there a better/right way of doing this that I'm missing?
For some reason this feel like a bit of a hack to me :(

Thanks in advance, 

Russell

-- 
echo http://russell.rucus.net/spam/ | sed 's,t/.*,t,;P;s,.*//,,;s,\.,@,;'

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to