Browse files

Refactored models a tiny bit.

  • Loading branch information...
1 parent 0cb95b0 commit 2eb0480c97ae516385b96a5663746ecc5caf75d1 @djm djm committed Dec 6, 2010
Showing with 84 additions and 17 deletions.
  1. +59 −0 main/migrations/0005_changed_choices_to_an_int_field.py
  2. +20 −13 main/models.py
  3. +1 −1 templates/main/project.html
  4. +4 −3 urls.py
View
59 main/migrations/0005_changed_choices_to_an_int_field.py
@@ -0,0 +1,59 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Changing field 'PageVersion.status'
+ db.alter_column('main_pageversion', 'status', self.gf('django.db.models.fields.IntegerField')())
+
+
+ def backwards(self, orm):
+
+ # Changing field 'PageVersion.status'
+ db.alter_column('main_pageversion', 'status', self.gf('django.db.models.fields.CharField')(max_length=32))
+
+
+ models = {
+ 'main.client': {
+ 'Meta': {'object_name': 'Client'},
+ 'created_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '50', 'db_index': 'True'})
+ },
+ 'main.page': {
+ 'Meta': {'ordering': "('-display_order',)", 'object_name': 'Page'},
+ 'created_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'display_order': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'project': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['main.Project']"})
+ },
+ 'main.pageversion': {
+ 'Meta': {'object_name': 'PageVersion'},
+ 'approval_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+ 'created_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'image': ('django.db.models.fields.files.ImageField', [], {'max_length': '100'}),
+ 'number': ('django.db.models.fields.IntegerField', [], {'default': '1'}),
+ 'page': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['main.Page']"}),
+ 'status': ('django.db.models.fields.IntegerField', [], {'default': '1'})
+ },
+ 'main.project': {
+ 'Meta': {'object_name': 'Project'},
+ 'client': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['main.Client']"}),
+ 'created_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '50', 'db_index': 'True'})
+ }
+ }
+
+ complete_apps = ['main']
View
33 main/models.py
@@ -1,4 +1,6 @@
from django.db import models
+from django.utils.translation import ugettext as _
+
class Client(models.Model):
name = models.CharField(max_length=255)
@@ -8,21 +10,24 @@ class Client(models.Model):
def __unicode__(self):
return self.name
+
class Project(models.Model):
- client = models.ForeignKey(Client)
+ client = models.ForeignKey('main.Client')
name = models.CharField(max_length=255)
slug = models.SlugField(max_length=50, unique=True)
description = models.TextField(blank=True)
created_date = models.DateTimeField(auto_now_add=True)
def __unicode__(self):
- return "%s (%s)" % (self.name, self.client.name)
+ return u"%s (%s)" % (self.name, self.client.name)
+ @models.permalink
def get_absolute_url(self):
- return "/%s/%s/" % (self.client.slug, self.slug)
+ return ('main-project', [self.client.slug, self.slug])
+
class Page(models.Model):
- project = models.ForeignKey(Project)
+ project = models.ForeignKey('main.Project')
name = models.CharField(max_length=255)
description = models.TextField(blank=True)
display_order = models.IntegerField(default=0)
@@ -32,23 +37,25 @@ class Meta:
ordering = ('-display_order',)
def __unicode__(self):
- return "%s (%s / %s)" % (self.name, self.project.client.name, self.project.name)
+ return u"%s (%s / %s)" % (self.name, self.project.client.name,
+ self.project.name)
- def get_versions(self):
- return self.pageversion_set.all()
class PageVersion(models.Model):
+ OPEN, APPROVED, REJECTED = range(1, 4)
STATUS_CHOICES = (
- ('Open', 'Under review'),
- ('Appproved', 'Approved'),
- ('Rejected', 'Rejected'),
+ (OPEN, _("Under review")),
+ (APPROVED, _("Approved")),
+ (REJECTED, _("Rejected")),
)
- page = models.ForeignKey(Page)
+ page = models.ForeignKey('main.Page')
number = models.IntegerField(default=1)
image = models.ImageField(upload_to='designs/%Y/%m/%d')
- status = models.CharField(max_length=32, default='Open', choices=STATUS_CHOICES)
+ status = models.IntegerField(default=OPEN, choices=STATUS_CHOICES)
created_date = models.DateTimeField(auto_now_add=True)
approval_date = models.DateTimeField(null=True, blank=True)
def __unicode__(self):
- return "Version #%d of '%s' (%s / %s)" % (self.number, self.page.name, self.page.project.client.name, self.page.project.name)
+ return u"Version #%d of '%s' (%s / %s)" % (self.number, self.page.name,
+ self.page.project.client.name,
+ self.page.project.name)
View
2 templates/main/project.html
@@ -11,7 +11,7 @@
'description': '{{ page.description|escapejs }}',
};
versions = [];
- {% for version in page.get_versions %}
+ {% for version in page.pageversion_set.all %}
versions.push({
'url': '{{ version.image.url|escapejs }}',
'number': '{{ version.number|escapejs }}'
View
7 urls.py
@@ -10,12 +10,13 @@
# Uncomment the admin/doc line below to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),
- (r'^admin/', include(admin.site.urls)),
- (r'(?P<client_slug>[\w-]*)/(?P<project_slug>[\w-]*)/', 'main.views.project'),
+ url(r'^admin/', include(admin.site.urls)),
+ url(r'(?P<client_slug>[\w-]*)/(?P<project_slug>[\w-]*)/', 'main.views.project',
+ name='main-project'),
)
if settings.DEBUG:
urlpatterns += patterns('django.views.static',
- (r'^media/(?P<path>.*)$', 'serve',
+ url(r'^media/(?P<path>.*)$', 'serve',
{'document_root': settings.MEDIA_ROOT}),
)

0 comments on commit 2eb0480

Please sign in to comment.