Last modified: Jan 10, 2023 By Alexander Williams

Django DateField 6 simple Examples

Example 1


class Priority(models.Model):
    name = models.CharField(max_length=30)
    created_at = models.DateField(auto_now_add=True)
    updated_at = models.DateField(auto_now=True)
    active = models.BooleanField(default=True)

Example 2


class Clarksontimefixture(models.Model):
    assesed12month = models.TextField()
    thisweekMonthly = models.TextField()
    thisweekDaily = models.TextField()
    lastweekMonthly = models.TextField()
    lastweekDaily = models.TextField()
    week = models.IntegerField()
    year = models.IntegerField()
    start_date = models.DateField(null = True)
    end_date = models.DateField(null = True)

Example 3


class Clarksonspotfixture(models.Model):
    Vessel = models.TextField()
    CBM = models.TextField()
    Cargo = models.TextField()
    Voyage = models.TextField()
    Laycan = models.TextField()
    Rate=models.TextField()
    Charterer=models.TextField()
    week = models.IntegerField()
    year = models.IntegerField()
    start_date = models.DateField(null = True)
    end_date = models.DateField(null = True)
    class Meta:
        db_table = 'Clarksonspotfixture'

Example 4


class ProbationTypes(models.Model):
    name = models.CharField(max_length=30)
    created_at = models.DateField(auto_now_add=True)
    updated_at = models.DateField(auto_now=True)
    active = models.BooleanField(default=True)

Example 5


class Contracts(models.Model):
    contractType = models.ForeignKey(ContractTypes)
    project = models.ForeignKey(Projects)
    name =  models.CharField(max_length=200, null=False)
    fullPrice = models.IntegerField(null=True)
    startDate = models.DateField(null=True)
    status = models.CharField(max_length=200, null=True)

    class Meta:
        permissions = (
            ("viewContract", "Access to contract view"),
        )

Example 6


class Gas(models.Model):
    aadhar = models.ForeignKey(UserList, on_delete=models.CASCADE)
    bill_date = models.DateField()
    due_date = models.DateField()
    bill = models.IntegerField()
    consumption = models.IntegerField()
    status = models.IntegerField()

    def __str__(self):
        return str(self.aadhar) + ' - ' + str(self.status)