Created
March 8, 2011 22:17
-
-
Save huseyinyilmaz/861209 to your computer and use it in GitHub Desktop.
django models.py file for a sample prefilled database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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