def test_binary_field(self): field = models.BinaryField() name, path, args, kwargs = field.deconstruct() self.assertEqual(path, "djmodels.db.models.BinaryField") self.assertEqual(args, []) self.assertEqual(kwargs, {}) field = models.BinaryField(editable=True) name, path, args, kwargs = field.deconstruct() self.assertEqual(args, []) self.assertEqual(kwargs, {'editable': True})
class NullableFields(models.Model): # Fields in db.backends.oracle.BulkInsertMapper big_int_filed = models.BigIntegerField(null=True, default=1) binary_field = models.BinaryField(null=True, default=b'data') date_field = models.DateField(null=True, default=timezone.now) datetime_field = models.DateTimeField(null=True, default=timezone.now) decimal_field = models.DecimalField(null=True, max_digits=2, decimal_places=1, default=Decimal('1.1')) duration_field = models.DurationField(null=True, default=datetime.timedelta(1)) float_field = models.FloatField(null=True, default=3.2) integer_field = models.IntegerField(null=True, default=2) null_boolean_field = models.BooleanField(null=True, default=False) null_boolean_field_old = models.NullBooleanField(null=True, default=False) positive_integer_field = models.PositiveIntegerField(null=True, default=3) positive_small_integer_field = models.PositiveSmallIntegerField(null=True, default=4) small_integer_field = models.SmallIntegerField(null=True, default=5) time_field = models.TimeField(null=True, default=timezone.now) # Fields not required in BulkInsertMapper char_field = models.CharField(null=True, max_length=4, default='char') email_field = models.EmailField(null=True, default='*****@*****.**') file_field = models.FileField(null=True, default='file.txt') file_path_field = models.FilePathField(path='/tmp', null=True, default='file.txt') generic_ip_address_field = models.GenericIPAddressField(null=True, default='127.0.0.1') if Image: image_field = models.ImageField(null=True, default='image.jpg') slug_field = models.SlugField(null=True, default='slug') text_field = models.TextField(null=True, default='text') url_field = models.URLField(null=True, default='/') uuid_field = models.UUIDField(null=True, default=uuid.uuid4)
class Reporter(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30) email = models.EmailField() facebook_user_id = models.BigIntegerField(null=True) raw_data = models.BinaryField(null=True) small_int = models.SmallIntegerField() class Meta: unique_together = ('first_name', 'last_name') def __str__(self): return "%s %s" % (self.first_name, self.last_name)
class AllFieldsModel(models.Model): big_integer = models.BigIntegerField() binary = models.BinaryField() boolean = models.BooleanField(default=False) char = models.CharField(max_length=10) date = models.DateField() datetime = models.DateTimeField() decimal = models.DecimalField(decimal_places=2, max_digits=2) duration = models.DurationField() email = models.EmailField() file_path = models.FilePathField() floatf = models.FloatField() integer = models.IntegerField() generic_ip = models.GenericIPAddressField() null_boolean = models.NullBooleanField() positive_integer = models.PositiveIntegerField() positive_small_integer = models.PositiveSmallIntegerField() slug = models.SlugField() small_integer = models.SmallIntegerField() text = models.TextField() time = models.TimeField() url = models.URLField() uuid = models.UUIDField() fo = ForeignObject('self', on_delete=models.CASCADE, from_fields=['abstract_non_concrete_id'], to_fields=['id'], related_name='reverse') fk = ForeignKey('self', models.CASCADE, related_name='reverse2') m2m = ManyToManyField('self') oto = OneToOneField('self', models.CASCADE) object_id = models.PositiveIntegerField() content_type = models.ForeignKey(ContentType, models.CASCADE) gfk = GenericForeignKey() gr = GenericRelation(DataModel)
class CaseTestModel(models.Model): integer = models.IntegerField() integer2 = models.IntegerField(null=True) string = models.CharField(max_length=100, default='') big_integer = models.BigIntegerField(null=True) binary = models.BinaryField(default=b'') boolean = models.BooleanField(default=False) date = models.DateField(null=True, db_column='date_field') date_time = models.DateTimeField(null=True) decimal = models.DecimalField(max_digits=2, decimal_places=1, null=True, db_column='decimal_field') duration = models.DurationField(null=True) email = models.EmailField(default='') file = models.FileField(null=True, db_column='file_field') file_path = models.FilePathField(null=True) float = models.FloatField(null=True, db_column='float_field') if Image: image = models.ImageField(null=True) generic_ip_address = models.GenericIPAddressField(null=True) null_boolean = models.BooleanField(null=True) null_boolean_old = models.NullBooleanField() positive_integer = models.PositiveIntegerField(null=True) positive_small_integer = models.PositiveSmallIntegerField(null=True) slug = models.SlugField(default='') small_integer = models.SmallIntegerField(null=True) text = models.TextField(default='') time = models.TimeField(null=True, db_column='time_field') url = models.URLField(default='') uuid = models.UUIDField(null=True) fk = models.ForeignKey('self', models.CASCADE, null=True) def __str__(self): return "%i, %s" % (self.integer, self.string)
class RawData(models.Model): raw_data = models.BinaryField()
class BinaryData(models.Model): data = models.BinaryField(null=True)
class DataModel(models.Model): short_data = models.BinaryField(max_length=10, default=b'\x08') data = models.BinaryField()