Skip to content

Instantly share code, notes, and snippets.

@huseyinyilmaz
Created March 8, 2011 22:17
Show Gist options
  • Save huseyinyilmaz/861209 to your computer and use it in GitHub Desktop.
Save huseyinyilmaz/861209 to your computer and use it in GitHub Desktop.
django models.py file for a sample prefilled database
from django.db import models
class Company(models.Model):
name = models.CharField(max_length=255,unique=True)
class Department(models.Model):
name = models.CharField(max_length=255)
company = models.ForeignKey(Company)
class Meta():
unique_together = (('name','company'))
class Employee(models.Model):
name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255)
birthday = models.DateTimeField()
department = models.ForeignKey(Department)
def fillDB():
import datetime
for i in range(10):
print 'Company %d'%i
company = Company(name="company%d"%i)
company.save()
for j in range(10+i%10):
print 'department %d'%j
department = Department(name='department%d'%j,company=company)
department.save()
for k in range(50+j):
val = i+j+k
employee = Employee(name='employee name %d'%k,
last_name='employee lastname %d'%k,
birthday=datetime.datetime(1900+(val%100),(val%12)+1,(val%28)+1),
department=department)
employee.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment