示例#1
0
    class Book(models.Model):
        __tablename__ = 'good_books'

        id = fields.AutoField()
        author = fields.ForeignKeyField(Author,
                                        'books',
                                        is_nullable=True,
                                        on_delete=sql.CASCADE)
        title = fields.CharField(default='Title')
        pages = fields.IntegerField(default=100)
        coauthor = fields.ForeignKeyField(Author,
                                          'cobooks',
                                          is_nullable=True,
                                          on_delete=sql.NO_ACTION)
        rating = fields.IntegerField(default=10)
        name = fields.CharField(default='Book name')
示例#2
0
def test_typed_field_error():
    field = fields.CharField(name='str_field')
    with pytest.raises(FieldError):
        field.__set__(MockModel(), 1)
示例#3
0
def test_sized_field_error():
    field = fields.CharField(name='sized', max_length=1)
    with pytest.raises(FieldError):
        field.__set__(MockModel(), 'wqe')
示例#4
0
def test_field_is_nullable_and_has_no_default_raise_error():
    field = fields.CharField(name='field', is_nullable=False, default=None)
    with pytest.raises(FieldError):
        field.__set__(MockModel(), None)
示例#5
0
    class Author(models.Model):

        id = fields.AutoField()
        name = fields.CharField()