Пример #1
0
    def __new__(cls, name, bases, classdict):
        
        have_primary = False
        fields = OrderedDict()
        _primary = None
        for n, value in classdict.items():
            if isinstance(value, Field): 
                value.expressionBehaviour()  
                value.Name = n.lower() 
                fields[n] = value
                if primary.check(value):
                    have_primary = True
                    _primary = value
                elif n == "id":
                    raise ValueError("id must be primary!")

        if not have_primary:
            IdField = IntegerField(primary, autoinc)
            IdField.expressionBehaviour()
            classdict["id"] = IdField
            fields = OrderedDict([('id', IdField)] + list(fields.items()))
            _primary = IdField
        result = type.__new__(cls, name, bases, classdict)
        result._primary = _primary
        for f in fields.values():
            f.Model = result  
        
        result._fields = fields 
        result._own_type = result
        result.Name = SingletonProperty(name.lower())
        return result
Пример #2
0
 def test_bin(self):
     field = IntegerField()
     field.Model = Model()
     field.Model.Name = "test"
     field.expressionBehaviour()
     field.Name = "id"
     self.assertEqual(str(field > 1), "test.id > 1")
     self.assertEqual(str(field == 1), "test.id = 1")
     self.assertEqual(str(field < 1), "test.id < 1")
     self.assertEqual(str(field >= 1), "test.id >= 1")
     self.assertEqual(str(field <= 1), "test.id <= 1")
     self.assertEqual(str(field != 1), "test.id != 1")