commit b4808d2be9627d49041761ef5dae3969a027704f
Author: Vassilios Karakoidas <vassilios.karakoidas@gmail.com>
Date:   Tue Feb 22 19:33:04 2011 +0200

    * Image now includes Foreign Key relationship with VirtualMachine (sourcevm)
    * Fixed primary key ranges in db/db_test_data.json

diff --git a/db/fixtures/db_test_data.json b/db/fixtures/db_test_data.json
index 4fd427f..8c9b66e 100644
--- a/db/fixtures/db_test_data.json
+++ b/db/fixtures/db_test_data.json
@@ -1,20 +1,28 @@
 [
     {
         "model": "db.SynnefoUser",
-        "pk": 1,
+        "pk": 30000,
         "fields": {
             "name": "admin user",
-            "created": "2011-02-06 00:00:00",
-            "updated": "2011-02-06 00:00:00",
-            "credit": 1,
-            "monthly_rate": 1,
+            "credit": 0,
+            "created": "2011-02-06",
+            "monthly_rate": 10,
             "user" : 1,
             "violations" : 0
    	    }
     },
     {
+        "model" : "db.Limit",
+        "pk" : 30000,
+        "fields" : {
+            "name" : "QUOTA_CREDIT",
+            "user" : 1,
+            "value" : 100
+        }
+    },
+    {
         "model": "db.Flavor",
-        "pk": 1,
+        "pk": 30000,
         "fields": {
             "cpu": 1,
             "ram": 1024,
@@ -23,126 +31,186 @@
     },
     {
         "model": "db.Flavor",
-        "pk": 2,
+        "pk": 30001,
         "fields": {
             "cpu": 1,
             "ram": 1024,
-            "disk": 10
+            "disk": 20
+        }
+    },
+    {
+        "model" : "db.FlavorCostHistory",
+        "pk" : 30000,
+        "fields" : {
+            "cost_active" : 10,
+            "cost_inactive" : 5,
+            "effective_from" : "2011-01-01",
+            "flavor" : 30000
+        }
+    },
+    {
+        "model" : "db.FlavorCostHistory",
+        "pk" : 30001,
+        "fields" : {
+            "cost_active" : 2,
+            "cost_inactive" : 1,
+            "effective_from" : "2010-01-01",
+            "flavor" : 30000
         }
     },
     {
         "model": "db.VirtualMachine",
-        "pk": 1001,
+        "pk": 30000,
         "fields": {
             "name": "snf-1001",
             "created": "2011-02-06 00:00:00",
-            "updated": "2011-02-06 00:00:00",
             "charged": "2011-02-06 00:00:00",
-            "sourceimage": 1,
+            "sourceimage": 30000,
             "hostid": "HAL-9000",
             "description": "database server",
             "ipfour": "192.168.2.1",
             "ipsix": "::1",
-            "flavor": 1,
+            "flavor": 30000,
             "_operstate": "STOPPED"
         }
     },
     {
         "model": "db.VirtualMachine",
-        "pk": 1002,
+        "pk": 30001,
         "fields": {
             "name": "snf-1002",
             "created": "2011-02-10 00:00:00",
-            "updated": "2011-02-10 00:00:00",
             "charged": "2011-02-10 00:00:00",
-            "sourceimage": 1,
+            "sourceimage": 30000,
             "hostid": "HAL-9000",
             "description": "mail server",
             "ipfour": "192.168.2.2",
             "ipsix": "::2",
-            "flavor": 1,
+            "flavor": 30000,
             "_operstate": "BUILD"
         }
     },
     {
         "model": "db.VirtualMachine",
-        "pk": 1003,
+        "pk": 30002,
         "fields": {
             "name": "snf-1003",
-            "created": "2011-02-10 00:00:00",
-            "updated": "2011-02-10 00:00:00",
-            "charged": "2011-02-10 00:00:00",
-            "sourceimage": 1,
+            "created": "2009-02-10 00:00:00",
+            "charged": "2010-01-01 00:00:00",
+            "sourceimage": 30000,
             "hostid": "HAL-9000",
             "description": "my server",
             "ipfour": "192.168.2.3",
             "ipsix": "::3",
-            "flavor": 1,
+            "flavor": 30000,
             "_operstate": "STARTED"
         }
     },
     {
         "model": "db.VirtualMachine",
-        "pk": 1004,
+        "pk": 30003,
         "fields": {
             "name": "snf-1004",
             "created": "2011-02-10 00:00:00",
-            "updated": "2011-02-10 00:00:00",
             "charged": "2011-02-10 00:00:00",
-            "sourceimage": 1,
+            "sourceimage": 30000,
             "hostid": "HAL-9000",
             "description": "my 2nd server",
             "ipfour": "192.168.2.4",
             "ipsix": "::4",
-            "flavor": 1,
+            "flavor": 30000,
             "_operstate": "STARTED"
         }
     },
     {
+        "model" : "db.AccountingLog",
+        "pk" : 30000,
+        "fields" : {
+            "vm" : 30000,
+            "date" : "2010-01-01",
+            "state" : "STARTED"
+        }
+    },
+    {
+        "model" : "db.AccountingLog",
+        "pk" : 30001,
+        "fields" : {
+            "vm" : 30000,
+            "date" : "2011-02-01",
+            "state" : "STARTED"
+        }
+    },
+    {
+        "model" : "db.AccountingLog",
+        "pk" : 30002,
+        "fields" : {
+            "vm" : 30002,
+            "date" : "2010-01-01",
+            "state" : "STARTED"
+        }
+    },
+    {
+        "model" : "db.AccountingLog",
+        "pk" : 30003,
+        "fields" : {
+            "vm" : 30002,
+            "date" : "2010-03-01",
+            "state" : "STOPPED"
+        }
+    },
+    {
+        "model" : "db.AccountingLog",
+        "pk" : 30004,
+        "fields" : {
+            "vm" : 30002,
+            "date" : "2011-01-01",
+            "state" : "STARTED"
+        }
+    },
+    {
         "model": "db.Image",
-        "pk": 1,
+        "pk": 30000,
         "fields": {
             "name": "Debian Squeeze",
-            "created": "2011-02-06 00:00:00",
             "updated": "2011-02-06 00:00:00",
+            "created": "2011-02-06 00:00:00",
             "state": "ACTIVE",
-            "description": "Full Debian Squeeze Installation"
+            "description": "Full Debian Squeeze Installation",
+            "owner" : 30000
         }
     },
     {
         "model": "db.Image",
-        "pk": 2,
+        "pk": 30001,
         "fields": {
             "name": "Slackware 13.1",
-            "created": "2011-02-10 00:00:00",
             "updated": "2011-02-10 00:00:00",
+            "created": "2011-02-10 00:00:00",
             "state": "ACTIVE",
             "description": "Full Slackware 13.1 Installation",
-            "owner" : 1
+            "owner" : 30000
         }
     },   
     {
         "model": "db.Disk",
-        "pk": 1,
+        "pk": 30000,
         "fields": {
             "name": "My_Music",
             "created": "2011-02-10 00:00:00",
-            "updated": "2011-02-10 00:00:00",
-            "size" : "20",
-            "vm" : "1001",
-            "owner" : "1"
+            "size" : 20,
+            "vm" : 30000,
+            "owner" : 30000
         }
     }, 
     {
         "model": "db.Disk",
-        "pk": 2,
+        "pk": 30001,
         "fields": {
             "name": "My_Videos",
             "created": "2011-02-10 00:00:00",
-            "updated": "2011-02-10 00:00:00",
-            "size" : "300",
-            "vm" : "1001",
-            "owner" : "1"
+            "size" : 300,
+            "vm" : 30000,
+            "owner" : 30000
         }
     } 
-] 
+]
\ No newline at end of file
diff --git a/db/models.py b/db/models.py
index 319026f..049ab04 100644
--- a/db/models.py
+++ b/db/models.py
@@ -63,14 +63,14 @@ class SynnefoUser(models.Model):
             return limit_objs[0].value
         
         return 0
-        
+
 
 class Image(models.Model):
     # This is WIP, FIXME
     IMAGE_STATES = (
-                ('ACTIVE', 'Active'),
-                ('SAVING', 'Saving'),
-                ('DELETED', 'Deleted')
+        ('ACTIVE', 'Active'),
+        ('SAVING', 'Saving'),
+        ('DELETED', 'Deleted')
     )
 
     name = models.CharField(max_length=255, help_text=_('description'))
@@ -79,6 +79,7 @@ class Image(models.Model):
     owner = models.ForeignKey(SynnefoUser,blank=True, null=True)
     created = models.DateTimeField('Time of creation', auto_now_add=True)
     updated = models.DateTimeField('Time of last update', auto_now=True)
+    sourcevm = models.ForeignKey("VirtualMachine", null=True)
 
     class Meta:
         verbose_name = u'Image'
@@ -128,9 +129,9 @@ class Limit(models.Model):
 
 
 class Flavor(models.Model):
-    cpu = models.IntegerField(default=0)
-    ram = models.IntegerField(default=0)
-    disk = models.IntegerField(default=0)
+    cpu = models.IntegerField(default=0, unique=False)
+    ram = models.IntegerField(default=0, unique=False)
+    disk = models.IntegerField(default=0, unique=False)
     
     class Meta:
         verbose_name = u'Virtual machine flavor'
@@ -267,7 +268,7 @@ class VirtualMachine(models.Model):
     charged = models.DateTimeField('Time of last charge', default=datetime.datetime.now())
     # Use string reference to avoid circular ForeignKey def.
     # FIXME: "sourceimage" works, "image" causes validation errors. See "related_name" in the Django docs.
-    sourceimage = models.ForeignKey(Image, null=False) 
+    sourceimage = models.ForeignKey("Image", null=False) 
     hostid = models.CharField(max_length=100)
     description = models.TextField(help_text=_('description'))
     ipfour = models.IPAddressField()
