def save(self, *args, **kwargs):
        '''Make sure that the term is valid.
        If changed, create a QualifiedDublinCoreElementHistory object and save it.
        '''
        if not self.term in self.DCELEMENT_CODE_MAP:
            raise ValueError('Extended Dublin Core Terms such as '+self.DCTERM_CODE_MAP[self.term]+' are not allowed. Please use only Dublin Core Elements')
        #HOW TO TELL IF OBJECT CHANGED? RETRIEVE FROM DB and COMPARE
        changed = False
        if self.pk:# existing object
            db_self = QualifiedDublinCoreElement.objects.get(pk=self.pk)
            #compare values, if changed set changed!
            if self.term != db_self.term:
                raise ValueError('Can not change DC element')
            if self.content != db_self.content:
                changed = True
            if self.qualifier != db_self.qualifier:
                changed = True
            if changed:
                hist = QualifiedDublinCoreElementHistory()
                hist.qdce = self
                hist.object_id = db_self.object_id
                hist.content_type = db_self.content_type
                hist.term = db_self.term
                hist.qualifier = db_self.qualifier
                hist.content  = db_self.content
                hist.save()
        super(QualifiedDublinCoreElement, self).save(*args, **kwargs)
        obj = self.content_object
        if hasattr(obj, '_save_dc_xml_file'):
            obj._save_dc_xml_file()
def save ( self , * args , ** kwargs ) : if not self . term in self . DCELEMENT_CODE_MAP : raise ValueError ( 'Extended Dublin Core Terms such as ' + self . DCTERM_CODE_MAP [ self . term ] + ' are not allowed. Please use only Dublin Core Elements' ) changed = False if self . pk : db_self = QualifiedDublinCoreElement . objects . get ( pk = self . pk ) if self . term != db_self . term : raise ValueError ( 'Can not change DC element' ) if self . content != db_self . content : changed = True if self . qualifier != db_self . qualifier : changed = True if changed : hist = QualifiedDublinCoreElementHistory ( ) hist . qdce = self hist . object_id = db_self . object_id hist . content_type = db_self . content_type hist . term = db_self . term hist . qualifier = db_self . qualifier hist . content = db_self . content hist . save ( ) super ( QualifiedDublinCoreElement , self ) . save ( * args , ** kwargs ) obj = self . content_object if hasattr ( obj , '_save_dc_xml_file' ) : obj . _save_dc_xml_file ( )
Make sure that the term is valid.
        If changed, create a QualifiedDublinCoreElementHistory object and save it.