Cleaned up models.

This commit is contained in:
Martin Mahner 2013-08-15 19:06:15 +02:00
parent 9b1d06a919
commit 1d6fea38c4
2 changed files with 42 additions and 5 deletions

View file

@ -0,0 +1,39 @@
# -*- coding: 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):
# Deleting field 'Snippet.content_highlighted'
db.delete_column(u'dpaste_snippet', 'content_highlighted')
def backwards(self, orm):
# Adding field 'Snippet.content_highlighted'
db.add_column(u'dpaste_snippet', 'content_highlighted',
self.gf('django.db.models.fields.TextField')(default='', blank=True),
keep_default=False)
models = {
u'dpaste.snippet': {
'Meta': {'ordering': "('-published',)", 'object_name': 'Snippet'},
'content': ('django.db.models.fields.TextField', [], {}),
'expires': ('django.db.models.fields.DateTimeField', [], {'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
'lexer': ('django.db.models.fields.CharField', [], {'default': "'Python'", 'max_length': '30'}),
'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': u"orm['dpaste.Snippet']"}),
'published': ('django.db.models.fields.DateTimeField', [], {'blank': 'True'}),
'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
'secret_id': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'})
}
}
complete_apps = ['dpaste']

View file

@ -13,10 +13,9 @@ def generate_secret_id(length=5):
class Snippet(models.Model):
secret_id = models.CharField(_(u'Secret ID'), max_length=255, blank=True)
content = models.TextField(_(u'Content'), )
content_highlighted = models.TextField(_(u'Highlighted Content'), blank=True)
lexer = models.CharField(_(u'Lexer'), max_length=30, default=LEXER_DEFAULT)
published = models.DateTimeField(_(u'Published'), blank=True)
expires = models.DateTimeField(_(u'Expires'), blank=True, help_text='asdf')
expires = models.DateTimeField(_(u'Expires'), blank=True)
parent = models.ForeignKey('self', null=True, blank=True, related_name='children')
class Meta:
@ -27,7 +26,7 @@ class Snippet(models.Model):
return len(self.content.splitlines())
def content_splitted(self):
return self.content_highlighted.splitlines()
return self.content.splitlines()
@property
def is_single(self):
@ -37,13 +36,12 @@ class Snippet(models.Model):
if not self.pk:
self.published = datetime.datetime.now()
self.secret_id = generate_secret_id()
self.content_highlighted = self.content
super(Snippet, self).save(*args, **kwargs)
def get_absolute_url(self):
return reverse('snippet_details', kwargs={'snippet_id': self.secret_id})
def __unicode__(self):
return '%s' % self.secret_id
return self.secret_id
mptt.register(Snippet, order_insertion_by=['content'])