Exemple #1
0
 def get_update_type(self, lookups, value):
     lookup = lookups[0]
     if lookup == '':
         return F(self.name).cat(V(Json(value)))
     if lookup == 'del':
         if '__' in value:
             values = value.split('__')
             return F(self.name).delete(V(values))
         return F(self.name) - V(value)
     raise ValueError('Update lookup type %s not found for field %s' %
                      (lookup, self.name))
Exemple #2
0
 def get_update_type(self, lookups, value):
     lookup = lookups[0]
     if lookup == '' or lookup == 'raw':
         keys = list(value.keys())
         values = list(value.values())
         if lookup == '':
             values = [str(v) for v in value.values()]
         return F(self.name).cat(HStore(V(keys), V(values)))
     if lookup == 'del':
         return Delete(self.name, value)
     raise ValueError('Update lookup type %s not found for field %s' %
                      (lookup, self.name))
Exemple #3
0
 def __init__(self, *values, **extra):
     values = list(values)
     for i, value in enumerate(values):
         if not isinstance(value, Expression):
             values[i] = V(value)
     super(CustomFunc, self).__init__(*values, **extra)
 def test_array_int_double_cat(self):
     with transaction.atomic():
         self.queryset.update(prices=V(-1).cat(F('prices').cat(V(3))))
     product = self.queryset.get()
     self.assertListEqual(product.prices, [-1, 0, 1, 2, 3])
 def test_array_int_cat_append_list(self):
     with transaction.atomic():
         self.queryset.update(prices=F('prices').cat(V([3, 4])))
     product = self.queryset.get()
     self.assertListEqual(product.prices, [0,1,2, 3, 4])
 def test_array_char_raises(self):
     with transaction.atomic():
         self.assertRaises((ProgrammingError), self.queryset.update, tags=F('tags').cat(V(1)))
 def test_array_cat_append(self):
     with transaction.atomic():
         self.queryset.update(tags=F('tags').cat(V(['Popular'], output_field = Product._meta.get_field('tags'))))
     product = self.queryset.get()
     self.assertListEqual(product.tags, ['Music', 'Album', 'Rock', 'Popular'])