class SizeFieldModel(Model): binary1 = SizedBinaryField(size_class=1) binary2 = SizedBinaryField(size_class=2) binary3 = SizedBinaryField(size_class=3) binary4 = SizedBinaryField(size_class=4) text1 = SizedTextField(size_class=1) text2 = SizedTextField(size_class=2) text3 = SizedTextField(size_class=3) text4 = SizedTextField(size_class=4)
def test_makemigrations_size_class_implicit(self): field = SizedTextField() statement, imports = MigrationWriter.serialize(field) assert ( statement == "django_mysql.models.SizedTextField(size_class=4)" )
class Migration(migrations.Migration): dependencies = [ ('testapp', '0001_initial'), ] operations = [ migrations.AlterField(model_name='sizedtextaltermodel', name='field', field=SizedTextField(size_class=1)), ]
class Migration(migrations.Migration): dependencies = [("testapp", "0001_initial")] operations = [ migrations.AlterField( model_name="sizedtextaltermodel", name="field", field=SizedTextField(size_class=1), ) ]
class article(models.Model): title = models.CharField(max_length=100, unique=True) slug = models.SlugField(max_length=100, unique=True) body = SizedTextField(3) publisher = models.CharField(max_length=15) #tags for searching tags = ListCharField(base_field=models.CharField(max_length=10), size=6, max_length=(6 * 11)) pub_date = models.DateTimeField('date published') def __str__(self): return self.body # TO CHECK IF ARTICLE PUBLISHED RECENTLY def was_published_recently(self): return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
class Migration(migrations.Migration): dependencies = [] operations = [ migrations.CreateModel( name='SizedTextAlterModel', fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('field', SizedTextField(size_class=3)), ], options={ }, bases=(models.Model,), ), ]
class Migration(migrations.Migration): dependencies = [] operations = [ migrations.CreateModel( name="SizedTextAlterModel", fields=[ ( "id", models.AutoField( verbose_name="ID", serialize=False, auto_created=True, primary_key=True, ), ), ("field", SizedTextField(size_class=3)), ], options={}, bases=(models.Model, ), ) ]
def test_deconstruct_size_class_2(self): field = SizedTextField(size_class=2) name, path, args, kwargs = field.deconstruct() new = SizedTextField(*args, **kwargs) assert new.size_class == field.size_class
def test_deconstruct_path(self): field = SizedTextField(size_class=1) name, path, args, kwargs = field.deconstruct() assert path == 'django_mysql.models.SizedTextField'
def test_textfield_default_length(self): # By default, SizedTextField should act like TextField field = SizedTextField() assert field.size_class == 4 assert field.db_type(None) == 'longtext'
class InvalidSizedTextModel(TemporaryModel): field = SizedTextField(size_class=5)
class Invalid(models.Model): field = SizedTextField(size_class=5)