本文整理汇总了Python中django.db.models.CharField类的典型用法代码示例。如果您正苦于以下问题:Python CharField类的具体用法?Python CharField怎么用?Python CharField使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CharField类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ready
def ready(self):
# Connections may already exist before we are called.
for conn in connections.all():
if conn.connection is not None:
register_type_handlers(conn)
connection_created.connect(register_type_handlers)
CharField.register_lookup(Unaccent)
TextField.register_lookup(Unaccent)
CharField.register_lookup(SearchLookup)
TextField.register_lookup(SearchLookup)
CharField.register_lookup(TrigramSimilar)
TextField.register_lookup(TrigramSimilar)
示例2: __init__
def __init__(self, *args, **kwargs):
kwargs.setdefault('editable', True)
kwargs.setdefault('verbose_name', _('Initials'))
kwargs.setdefault('max_length', 3)
kwargs.setdefault(
'help_text', _('Type 2-3 letters, all in uppercase and no spaces'))
CharField.__init__(self, *args, **kwargs)
示例3: __init__
def __init__(self, based_fields=None, zoom=None, suffix='',
max_length=63, *args, **kwargs):
super(PlainLocationField, self).__init__(based_fields=based_fields,
zoom=zoom, suffix=suffix, *args, **kwargs)
CharField.__init__(self, max_length=max_length, *args, **kwargs)
示例4: __init__
def __init__(self, *args, **kwargs):
kwargs.setdefault('editable', False)
kwargs.setdefault('blank', True)
kwargs.setdefault('max_length', 50)
kwargs.setdefault('verbose_name', 'Hostname')
kwargs.setdefault('default', socket.gethostname())
CharField.__init__(self, *args, **kwargs)
示例5: __init__
def __init__(self, *args, **kwargs):
kwargs.setdefault('verbose_name', _('What type of identity number is this?'))
kwargs.setdefault('editable', True)
kwargs.setdefault('max_length', 15)
kwargs.setdefault('choices', IDENTITY_TYPE)
# kwargs.setdefault('help_text', _('Format is 9999[12]9999'))
CharField.__init__(self, *args, **kwargs)
示例6: __init__
def __init__(self, *args, **kwargs):
kwargs.setdefault('editable', False)
kwargs.setdefault('blank', True)
kwargs.setdefault('null', True)
kwargs.setdefault('max_length', 150)
kwargs.setdefault('verbose_name', 'Revision')
CharField.__init__(self, *args, **kwargs)
示例7: __init__
def __init__(self, max_length=63, *args, **kwargs):
super(PlainLocationField, self).__init__(*args, **kwargs)
kwargs.pop('based_fields', None)
kwargs.pop('zoom', None)
kwargs.pop('suffix', None)
CharField.__init__(self, max_length=max_length, *args, **kwargs)
示例8: __init__
def __init__(self, *args, **kwargs):
kwargs['max_length'] = kwargs.get('max_length', 32 )
try:
self.auto = kwargs['auto']
del kwargs['auto']
except KeyError:
self.auto = True
CharField.__init__(self, *args, **kwargs)
示例9: contribute_to_class
def contribute_to_class(self, cls, name):
self.name = name
self.fk_field_name = name + '_fk'
self.ft_field_name = name + '_ft'
setattr(cls, name, self)
fk_field = ForeignKey(self.foreign_model, blank=True, null=True)
fk_field.contribute_to_class(cls, self.fk_field_name)
ft_field = CharField(max_length=255, blank=True)
ft_field.contribute_to_class(cls, self.ft_field_name)
示例10: __init__
def __init__(self, verbose_name=None, name=None, auto=True, version=1, node=None, clock_seq=None, namespace=None, **kwargs):
kwargs['max_length'] = 36
if auto:
kwargs['blank'] = True
kwargs.setdefault('editable', False)
self.version = version
if version==1:
self.node, self.clock_seq = node, clock_seq
elif version==3 or version==5:
self.namespace, self.name = namespace, name
CharField.__init__(self, verbose_name, name, **kwargs)
示例11: test_transform
def test_transform(self):
query = Query(Author)
CharField.register_lookup(Lower, 'lower')
try:
where = query.build_where(~Q(name__lower='foo'))
finally:
CharField._unregister_lookup(Lower, 'lower')
lookup = where.children[0]
self.assertIsInstance(lookup, Exact)
self.assertIsInstance(lookup.lhs, Lower)
self.assertIsInstance(lookup.lhs.lhs, SimpleCol)
self.assertEqual(lookup.lhs.lhs.target, Author._meta.get_field('name'))
示例12: test_transform
def test_transform(self):
new_name = self.t1.name.upper()
self.assertNotEqual(self.t1.name, new_name)
Tag.objects.create(name=new_name)
CharField.register_lookup(Lower)
try:
self.assertCountEqual(
Tag.objects.order_by().distinct('name__lower'),
[self.t1, self.t2, self.t3, self.t4, self.t5],
)
finally:
CharField._unregister_lookup(Lower)
示例13: contribute_to_class
def contribute_to_class(self, cls, name):
self.name = name
self.fk_field_name = name + '_fk'
self.ft_field_name = name + '_ft'
setattr(cls, name, self)
fk_kwargs = dict(blank=True, null=True)
if self.related_name:
fk_kwargs['related_name'] = self.related_name
fk_field = ForeignKey(self.foreign_model, **fk_kwargs)
fk_field.contribute_to_class(cls, self.fk_field_name)
ft_field = CharField(max_length=255, blank=True, null=True, default='')
ft_field.contribute_to_class(cls, self.ft_field_name)
示例14: test_length_transform
def test_length_transform(self):
try:
CharField.register_lookup(Length, 'length')
Author.objects.create(name='John Smith', alias='smithj')
Author.objects.create(name='Rhonda')
authors = Author.objects.filter(name__length__gt=7)
self.assertQuerysetEqual(
authors.order_by('name'), [
'John Smith',
],
lambda a: a.name
)
finally:
CharField._unregister_lookup(Length, 'length')
示例15: test_upper_transform
def test_upper_transform(self):
try:
CharField.register_lookup(Upper, 'upper')
Author.objects.create(name='John Smith', alias='smithj')
Author.objects.create(name='Rhonda')
authors = Author.objects.filter(name__upper__exact='JOHN SMITH')
self.assertQuerysetEqual(
authors.order_by('name'), [
'John Smith',
],
lambda a: a.name
)
finally:
CharField._unregister_lookup(Upper, 'upper')