Interview Questions

Python - Django Model Creation

The following code illustrates a sample ORM object model in Django.
This class can be used for persisting objects in DB.

from django.db import models
import datetime,uuid

class Device(models.Model):
    id = models.CharField(max_length=70,primary_key=True)
    name = models.CharField(max_length=70)
    status = models.CharField(max_length=70)
    ipAddress = models.CharField(default=False)
    createdOn = models.DateTimeField(,blank=True)
    def __unicode__(self):
    def save(self, *args, **kwargs):
        print "saving model Device" = uuid.uuid1()
        self.createdOn =
        super(Device, self).save(*args, **kwargs)
    class Meta:
        app_label = 'Tdd' # app name in django project
        db_table = 'Device' # table name for the model