First models work.

portnov [2008-06-07 03:44:26]
First models work.
Filename
mgmt/management.py
mgmt/models.py
settings.py
urls.py
diff --git a/mgmt/management.py b/mgmt/management.py
new file mode 100644
index 0000000..612db9c
--- /dev/null
+++ b/mgmt/management.py
@@ -0,0 +1,14 @@
+from django.db.models import signals
+from django.dispatch import dispatcher
+
+from models import *;
+
+def after_save(cls=None,instance=None):
+  if not cls or not instance:
+    return
+  if cls in [Project,Bug,Document]:
+    obj = Object(type=cls.__name__, oid=instance.id)
+    obj.save()
+
+dispatcher.connect(after_save, signal=signals.post_save)
+
diff --git a/mgmt/models.py b/mgmt/models.py
index f00e8b5..eadb7ed 100644
--- a/mgmt/models.py
+++ b/mgmt/models.py
@@ -1,5 +1,35 @@
 from django.db import models
+from django.contrib.auth.models import User

 class Object(models.Model):
   type = models.CharField(max_length=10)
   oid = models.IntegerField()
+
+class Project(models.Model):
+  name = models.CharField(max_length=64)
+  text = models.TextField()
+  repo = models.CharField(max_length=64)
+  admins = models.ManyToManyField(User,related_name='admin_projects')
+  team = models.ManyToManyField(User,related_name='in_projects')
+  class Admin:
+    pass
+
+class Bug(models.Model):
+  project = models.ForeignKey(Project)
+  author = models.ForeignKey(User,related_name='created_bugs')
+  confirmed = models.ForeignKey(User,related_name='confirmed_bugs')
+  responsible = models.ForeignKey(User,related_name='resp_bugs')
+  status = models.IntegerField()
+  title = models.CharField(max_length=64)
+  text = models.TextField()
+  class Admin:
+    pass
+
+class Document(models.Model):
+  project = models.ForeignKey(Project)
+  author = models.ForeignKey(User)
+  title = models.CharField(max_length=64)
+  text = models.TextField()
+  class Admin:
+    pass
+
diff --git a/settings.py b/settings.py
index 602e516..5539e59 100644
--- a/settings.py
+++ b/settings.py
@@ -66,7 +66,9 @@ TEMPLATE_DIRS = (

 INSTALLED_APPS = (
     'django.contrib.auth',
+    'django.contrib.admin',
     'django.contrib.contenttypes',
     'django.contrib.sessions',
     'django.contrib.sites',
+    'projects.mgmt',
 )
diff --git a/urls.py b/urls.py
index 5bd8335..a87c151 100644
--- a/urls.py
+++ b/urls.py
@@ -7,5 +7,5 @@ urlpatterns = patterns('',
     (r'^time/', current_time),

     # Uncomment this for admin:
-#     (r'^admin/', include('django.contrib.admin.urls')),
+    (r'^admin/', include('django.contrib.admin.urls')),
 )
ViewGit