Last modified: Jan 10, 2023 By Alexander Williams

Django IntegerField (Simple Examples)

Example 1:


class Author(models.Model):
    name = models.CharField(max_length=100)
    age = models.IntegerField()

Example 2:


class record(models.Model):
    worker_id = models.CharField(max_length=100)
    record_link_1 = models.CharField(max_length=100)
    record_link_2 = models.CharField(max_length=100)
    record_response = models.IntegerField()

Example 3:


class Accounts(AbstractBaseUser, PermissionsMixin):
    name = models.CharField(unique=True, max_length=20)
    salt = models.CharField(max_length=128, blank=True, null=True)
    pin = models.CharField(max_length=10, blank=True, null=True)
    pic = models.CharField(max_length=26, blank=True, null=True)
    loggedin = models.IntegerField(default=0)
    lastlogin = models.DateTimeField(blank=True, null=True)
    createdat = models.DateTimeField(auto_now_add=True)
    birthday = models.DateField(blank=True, null=True)
    banned = models.IntegerField(default=0)
    banreason = models.TextField(blank=True, null=True)
    gm = models.IntegerField(default=0)
    macs = models.TextField(blank=True, null=True)
    nxcredit = models.IntegerField(db_column='nxCredit', blank=True, null=True)  # Field name made lowercase.
    maplepoint = models.IntegerField(db_column='maplePoint', blank=True, null=True)  # Field name made lowercase.
    nxprepaid = models.IntegerField(db_column='nxPrepaid', blank=True, null=True)  # Field name made lowercase.
    characterslots = models.IntegerField(default=6)
    gender = models.IntegerField(default=0)
    tempban = models.DateTimeField(null=True, blank=True)
    greason = models.IntegerField(default=0)
    tos = models.IntegerField(default=1)
    is_staff=models.BooleanField(default=0)
    is_active=models.BooleanField(default=True)
    email = models.EmailField(blank=True, null=True)

    USERNAME_FIELD = 'name'

    objects = AccountManager()

    class Meta:
        managed = True
        db_table = 'accounts'

    def __unicode__(self):
        return self.name

    def get_full_name(self):
        return self.name

    def get_short_name(self):
        return self.name

example 4:


class Alliance(models.Model):
    name = models.CharField(max_length=13)
    notice = models.CharField(max_length=128)
    capacity = models.IntegerField()
    rank_title1 = models.CharField(max_length=45)
    rank_title2 = models.CharField(max_length=45)
    rank_title3 = models.CharField(max_length=45)
    rank_title4 = models.CharField(max_length=45)
    rank_title5 = models.CharField(max_length=45)
    guild1 = models.IntegerField()
    guild2 = models.IntegerField()
    guild3 = models.IntegerField()
    guild4 = models.IntegerField()
    guild5 = models.IntegerField()

    class Meta:
        managed = False
        db_table = 'alliance'

example 5:


class Buddies(models.Model):
    characterid = models.ForeignKey('Characters', db_column='characterid')
    buddyid = models.IntegerField()
    pending = models.IntegerField()
    group = models.CharField(max_length=17, blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'buddies'