コード例 #1
0
ファイル: models.py プロジェクト: ezc/django-mysql
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)
コード例 #2
0
    def test_makemigrations_size_class_implicit(self):
        field = SizedTextField()
        statement, imports = MigrationWriter.serialize(field)

        assert (
            statement ==
            "django_mysql.models.SizedTextField(size_class=4)"
        )
コード例 #3
0
class Migration(migrations.Migration):

    dependencies = [
        ('testapp', '0001_initial'),
    ]

    operations = [
        migrations.AlterField(model_name='sizedtextaltermodel',
                              name='field',
                              field=SizedTextField(size_class=1)),
    ]
コード例 #4
0
class Migration(migrations.Migration):

    dependencies = [("testapp", "0001_initial")]

    operations = [
        migrations.AlterField(
            model_name="sizedtextaltermodel",
            name="field",
            field=SizedTextField(size_class=1),
        )
    ]
コード例 #5
0
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)
コード例 #6
0
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,),
        ),
    ]
コード例 #7
0
ファイル: 0001_initial.py プロジェクト: saisai/django-mysql
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, ),
        )
    ]
コード例 #8
0
 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
コード例 #9
0
 def test_deconstruct_path(self):
     field = SizedTextField(size_class=1)
     name, path, args, kwargs = field.deconstruct()
     assert path == 'django_mysql.models.SizedTextField'
コード例 #10
0
 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'
コード例 #11
0
 class InvalidSizedTextModel(TemporaryModel):
     field = SizedTextField(size_class=5)
コード例 #12
0
 class Invalid(models.Model):
     field = SizedTextField(size_class=5)