Beispiel #1
0
class IterableFieldModel(models.Model):
    set_field = SetField(models.CharField(max_length=1))
    list_field = ListField(models.CharField(max_length=1))
    set_field_int = SetField(models.BigIntegerField(max_length=1))
    list_field_int = ListField(models.BigIntegerField(max_length=1))
    set_field_dt = SetField(models.DateTimeField())
    list_field_dt = ListField(models.DateTimeField())

    class Meta:
        app_label = "gcloudc"
Beispiel #2
0
class SpecialIndexesModel(models.Model):
    name = models.CharField(max_length=255, primary_key=True)
    nickname = CharField(blank=True)
    sample_list = ListField(models.CharField)

    def __str__(self):
        return self.name
    def test_all_fields_are_pickleable(self):
        """ In order to work with Djangae's migrations, all fields must be pickeable. """
        fields = [
            CharField(),
            CharOrNoneField(),
            ComputedBooleanField("method_name"),
            ComputedCharField("method_name"),
            ComputedIntegerField("method_name"),
            ComputedPositiveIntegerField("method_name"),
            ComputedTextField("method_name"),
            GenericRelationField(),
            JSONField(default=list),
            ListField(CharField(), default=["badger"]),
            SetField(CharField(), default=set(["badger"])),
        ]

        fields.extend([
            RelatedListField(ModelWithCharField),
            RelatedSetField(ModelWithCharField)
        ])

        for field in fields:
            try:
                pickle.dumps(field)
            except (pickle.PicklingError, TypeError) as e:
                self.fail("Could not pickle %r: %s" % (field, e))
Beispiel #4
0
class UniqueModel(models.Model):
    unique_field = models.CharField(max_length=100, unique=True)
    unique_combo_one = models.IntegerField(blank=True, default=0)
    unique_combo_two = models.CharField(max_length=100, blank=True, default="")

    unique_relation = models.ForeignKey('self',
                                        null=True,
                                        blank=True,
                                        unique=True,
                                        on_delete=models.DO_NOTHING)

    unique_set_field = SetField(models.CharField(max_length=500), unique=True)
    unique_list_field = ListField(models.CharField(max_length=500),
                                  unique=True)

    unique_together_list_field = ListField(models.IntegerField())

    class Meta:
        unique_together = [("unique_combo_one", "unique_combo_two"),
                           ("unique_together_list_field", "unique_combo_one")]
Beispiel #5
0
    def test_list_field(self):
        instance = IterableFieldModel.objects.create()
        self.assertEqual([], instance.list_field)
        instance.list_field.append("One")
        self.assertEqual(["One"], instance.list_field)
        instance.save()

        self.assertEqual(["One"], instance.list_field)

        instance = IterableFieldModel.objects.get(pk=instance.pk)
        self.assertEqual(["One"], instance.list_field)

        results = IterableFieldModel.objects.filter(list_field__contains="One")
        self.assertEqual([instance], list(results))

        self.assertEqual([1, 2],
                         ListField(models.IntegerField).to_python("[1, 2]"))
Beispiel #6
0
class IterableFieldsWithValidatorsModel(models.Model):
    set_field = SetField(models.CharField(max_length=100),
                         min_length=2,
                         max_length=3,
                         blank=False)
    list_field = ListField(models.CharField(max_length=100),
                           min_length=2,
                           max_length=3,
                           blank=False)
    related_set = RelatedSetField(ISOther,
                                  min_length=2,
                                  max_length=3,
                                  blank=False)
    related_list = RelatedListField(ISOther,
                                    related_name="iterable_list",
                                    min_length=2,
                                    max_length=3,
                                    blank=False)