How to use the peewee.CharField function in peewee

To help you get started, we’ve selected a few peewee examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github timster / peewee-moves / tests / test_tablecreator.py View on Github external
tc.column('text', 'col_text')
    tc.column('time', 'col_time')
    tc.column('uuid', 'col_uuid')

    assert isinstance(tc.model.id, peewee.AutoField)
    assert isinstance(tc.model.col_bare, peewee.BareField)
    assert isinstance(tc.model.col_biginteger, peewee.BigIntegerField)
    assert isinstance(tc.model.col_binary, peewee.BlobField)
    assert isinstance(tc.model.col_blob, peewee.BlobField)
    assert isinstance(tc.model.col_bool, peewee.BooleanField)
    assert isinstance(tc.model.col_char, peewee.CharField)
    assert isinstance(tc.model.col_date, peewee.DateField)
    assert isinstance(tc.model.col_datetime, peewee.DateTimeField)
    assert isinstance(tc.model.col_decimal, peewee.DecimalField)
    assert isinstance(tc.model.col_double, peewee.DoubleField)
    assert isinstance(tc.model.col_fixed, peewee.CharField)
    assert isinstance(tc.model.col_float, peewee.FloatField)
    assert isinstance(tc.model.col_int, peewee.IntegerField)
    assert isinstance(tc.model.col_integer, peewee.IntegerField)
    assert isinstance(tc.model.col_smallint, peewee.SmallIntegerField)
    assert isinstance(tc.model.col_smallinteger, peewee.SmallIntegerField)
    assert isinstance(tc.model.col_text, peewee.TextField)
    assert isinstance(tc.model.col_time, peewee.TimeField)
    assert isinstance(tc.model.col_uuid, peewee.UUIDField)
github Royal-Society-of-New-Zealand / NZ-ORCID-Hub / orcid_hub / models.py View on Github external
"""Get list of all types for UI drop-down option list."""
        return [(e.value, e.name.replace('_', ' ').title()) for e in cls]


class FundingRecord(RecordModel):
    """Funding record loaded from JSON file for batch processing."""

    task = ForeignKeyField(Task, related_name="funding_records", on_delete="CASCADE")
    title = CharField(max_length=255)
    translated_title = CharField(null=True, max_length=255)
    translated_title_language_code = CharField(null=True, max_length=10)
    type = CharField(max_length=255)
    organization_defined_type = CharField(null=True, max_length=255)
    short_description = CharField(null=True, max_length=4000)
    amount = CharField(null=True, max_length=255)
    currency = CharField(null=True, max_length=3)
    start_date = PartialDateField(null=True)
    end_date = PartialDateField(null=True)
    org_name = CharField(null=True, max_length=255, verbose_name="Organisation Name")
    city = CharField(null=True, max_length=255)
    region = CharField(null=True, max_length=255)
    country = CharField(null=True, max_length=255)
    disambiguated_org_identifier = CharField(null=True, max_length=255)
    disambiguation_source = CharField(null=True, max_length=255)
    is_active = BooleanField(
        default=False, help_text="The record is marked for batch processing", null=True)
    processed_at = DateTimeField(null=True)
    status = TextField(null=True, help_text="Record processing status.")

    def to_export_dict(self):
        """Map the funding record to dict for export into JSON/YAML."""
        org = self.task.org
github Royal-Society-of-New-Zealand / NZ-ORCID-Hub / orcid_hub / models.py View on Github external
oi.tuakiri_name = val(row, 12)

            oi.save()

        return reader.line_num - 1


class User(BaseModel, UserMixin, AuditMixin):
    """
    ORCiD Hub user.

    It's a gneric user including researchers, organisation administrators, hub administrators, etc.
    """

    name = CharField(max_length=64, null=True)
    first_name = CharField(null=True, verbose_name="First Name")
    last_name = CharField(null=True, verbose_name="Last Name")
    email = CharField(max_length=120, unique=True, null=True, verbose_name="Email Address")
    eppn = CharField(max_length=120, unique=True, null=True, verbose_name="EPPN")
    # ORCiD:
    orcid = OrcidIdField(null=True, verbose_name="ORCID iD", help_text="User's ORCID iD")
    confirmed = BooleanField(default=False)
    # Role bit-map:
    roles = SmallIntegerField(default=0)

    is_locked = BooleanField(default=False)
    webhook_enabled = BooleanField(default=False, null=True)
    orcid_updated_at = DateTimeField(null=True, default=None)

    # TODO: many-to-many
    # NB! depricated!
    # TODO: we still need to rememeber the rognanistiaon that last authenticated the user
github broadinstitute / cms / cms / util / db_helper.py View on Github external
def __str__(self):
        return self.name

class Population(ScanTable):
    super_population = pw.ForeignKeyField(SuperPopulation, null=True)

    name = pw.CharField(unique=True)

    def __str__(self):
        return self.name

class LocusInfo(ScanTable):
    '''
        Allele information for a given locus
    '''
    chrom                  = pw.CharField(max_length=32) 
    variant_id             = pw.CharField(max_length=64) 
    pos_bp                 = pw.IntegerField()
    map_pos_cm             = pw.DoubleField()
    ref_allele             = pw.CharField()
    alt_allele             = pw.CharField()
    ancestral_call         = pw.CharField(null=True)

    class Meta(object):
        indexes = (
            (('chrom','pos_bp','alt_allele'), True),
        )

    def __str__(self):
        return ",".join([str(self.chrom), str(self.variant_id), str(self.pos_bp), 
            str(self.map_pos_cm), str(self.ref_allele), str(self.alt_allele), 
            str(self.ancestral_call)])
github Royal-Society-of-New-Zealand / NZ-ORCID-Hub / orcid_hub / models.py View on Github external
return reader.line_num - 1


class User(BaseModel, UserMixin, AuditMixin):
    """
    ORCiD Hub user.

    It's a gneric user including researchers, organisation administrators, hub administrators, etc.
    """

    name = CharField(max_length=64, null=True)
    first_name = CharField(null=True, verbose_name="First Name")
    last_name = CharField(null=True, verbose_name="Last Name")
    email = CharField(max_length=120, unique=True, null=True, verbose_name="Email Address")
    eppn = CharField(max_length=120, unique=True, null=True, verbose_name="EPPN")
    # ORCiD:
    orcid = OrcidIdField(null=True, verbose_name="ORCID iD", help_text="User's ORCID iD")
    confirmed = BooleanField(default=False)
    # Role bit-map:
    roles = SmallIntegerField(default=0)

    is_locked = BooleanField(default=False)
    webhook_enabled = BooleanField(default=False, null=True)
    orcid_updated_at = DateTimeField(null=True, default=None)

    # TODO: many-to-many
    # NB! depricated!
    # TODO: we still need to rememeber the rognanistiaon that last authenticated the user
    organisation = ForeignKeyField(
        Organisation, related_name="members", on_delete="SET NULL", null=True)
    created_by = ForeignKeyField(DeferredUser, on_delete="SET NULL", null=True)
github dscovr / pyinstamation / pyinstamation / models.py View on Github external
date = datetime.datetime.now()
    delta = {
        'days': randrange(2, 3),
        'hours': randrange(1, 4),
        'minutes': randrange(1, 60)
    }
    return date + datetime.timedelta(**delta)


class BaseModel(orm.Model):
    class Meta:
        database = db


class User(BaseModel):
    username = orm.CharField(unique=True)
    likes = orm.IntegerField(default=0)
    followed = orm.IntegerField(default=0)
    unfollowed = orm.IntegerField(default=0)
    commented = orm.IntegerField(default=0)


class Follower(BaseModel):
    user = orm.ForeignKeyField(User)
    username = orm.CharField()
    unfollow_date = orm.DateTimeField(default=future_rand_date)
    following = orm.BooleanField(default=True)
    times_followed = orm.IntegerField(default=1)


class Statistics(BaseModel):
    user = orm.ForeignKeyField(User)
github Polsaker / throat / migrations / 001_initial.py View on Github external
class Meta:
            table_name = "api_token"

    @migrator.create_model
    class APITokenSettings(pw.Model):
        id = pw.AutoField()
        token = pw.ForeignKeyField(backref='apitokensettings_set', column_name='token_id', field='id', model=migrator.orm['api_token'])
        key = pw.CharField(max_length=255)
        value = pw.CharField(max_length=255)

        class Meta:
            table_name = "api_token_settings"

    @migrator.create_model
    class Client(pw.Model):
        client = pw.CharField(column_name='client_id', max_length=40, primary_key=True)
        _default_scopes = pw.TextField(null=True)
        _redirect_uris = pw.TextField(null=True)
        client_secret = pw.CharField(max_length=55, unique=True)
        is_confidential = pw.BooleanField(null=True)
        name = pw.CharField(max_length=40, null=True)
        user = pw.ForeignKeyField(backref='client_set', column_name='user_id', field='uid', model=migrator.orm['user'], null=True)

        class Meta:
            table_name = "client"

    @migrator.create_model
    class Grant(pw.Model):
        id = pw.AutoField()
        _scopes = pw.TextField(null=True)
        client = pw.ForeignKeyField(backref='grant_set', column_name='client_id', field='client', model=migrator.orm['client'])
        code = pw.CharField(index=True, max_length=255)
github felipevolpone / ray / examples / one-file-example / app.py View on Github external
    @classmethod
    def authenticate(cls, login_data):
        if login_data['username'] == 'ray' and login_data['password'] == 'charles':
            return {'username': 'ray'}

    @classmethod
    def salt_key(cls):
        return 'salt_key'


@endpoint('/post')
class Post(DBModel):
    hooks = [PostHook]

    title = peewee.CharField()
    description = peewee.CharField()


database.create_tables([Post], safe=True)


class PostShield(Shield):
    __model__ = Post

    def put(self, info):
        return info['username'] == 'ray'


class ActionPost(Action):
    __model__ = Post
github lettier / slackotron / src / models.py View on Github external
def direct_channel_user_name(self):
    if not self.is_direct:
        return ''
    if self.slack_name == 'USLACKBOT':
      return self.slack_name
    try:
      user = User.get(
          User.slack_id == self.slack_name
      )
      return user.slack_name
    except:
      return ''


class User(Base):
  slack_name = peewee.CharField()
  slack_id = peewee.CharField(unique=True)

  def channels(self):
    channels = Channel.select().join(
        ChannelUserRelationship
    ).where(
        ChannelUserRelationship.user == self
    )
    return channels


class Message(Base):
  text = peewee.CharField()
  slack_timestamp = peewee.CharField()
  channel = peewee.ForeignKeyField(Channel, related_name='messages')
  user = peewee.ForeignKeyField(User, related_name='messages')
github samael500 / aiochat / aiochat / chat / models.py View on Github external
import peewee
from datetime import datetime

from accounts.models import User
from helpers.models import BaseModel


class Room(BaseModel):

    """ Chat Room model """

    name = peewee.CharField(unique=True, index=True, max_length=32, null=False)

    @classmethod
    async def all_rooms(cls, objects):
        """ Return all rooms """
        return await objects.execute(cls.select())

    async def all_messages(self, objects):
        """ Return all messages """
        return await objects.prefetch(self.messages, User.select())

    class Meta:
        order_by = ('name', )

    def __str__(self):
        return self.name