Filter comment documents by current language
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 16 Oct 2013 10:40:18 +0000 (12:40 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 22 Oct 2013 07:49:53 +0000 (09:49 +0200)
comment/migrations/0002_auto__add_field_commentdocument_language_code.py [new file with mode: 0644]
comment/models.py
comment/views.py

diff --git a/comment/migrations/0002_auto__add_field_commentdocument_language_code.py b/comment/migrations/0002_auto__add_field_commentdocument_language_code.py
new file mode 100644 (file)
index 0000000..686f568
--- /dev/null
@@ -0,0 +1,34 @@
+# -*- 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):
+        # Adding field 'CommentDocument.language_code'
+        db.add_column(u'comment_commentdocument', 'language_code',
+                      self.gf('django.db.models.fields.CharField')(default='pl', max_length=2),
+                      keep_default=False)
+
+
+    def backwards(self, orm):
+        # Deleting field 'CommentDocument.language_code'
+        db.delete_column(u'comment_commentdocument', 'language_code')
+
+
+    models = {
+        u'comment.commentdocument': {
+            'Meta': {'ordering': "['order']", 'object_name': 'CommentDocument'},
+            'comment_id': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'language_code': ('django.db.models.fields.CharField', [], {'default': "'pl'", 'max_length': '2'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
+            'order': ('django.db.models.fields.IntegerField', [], {}),
+            'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '255'})
+        }
+    }
+
+    complete_apps = ['comment']
\ No newline at end of file
index a5c3000..4cbabfa 100644 (file)
@@ -7,6 +7,7 @@ class CommentDocument(models.Model):
     slug = models.SlugField(max_length = 255, unique = True)
     comment_id = models.CharField(max_length = 255, unique = True)
     order = models.IntegerField()
+    language_code = models.CharField(max_length = 2, default = 'pl')
 
     class Meta:
         ordering = ['order']
index 748f9c4..e494828 100644 (file)
@@ -1,5 +1,6 @@
 from django.views.generic import ListView, DetailView
 from django.conf import settings
+from django.utils.translation import get_language
 
 from .models import CommentDocument
 
@@ -7,6 +8,9 @@ from .models import CommentDocument
 class CommentDocumentList(ListView):
     model = CommentDocument
 
+    def get_queryset(self, **kwargs):
+        return super(CommentDocumentList, self).get_queryset(**kwargs).filter(language_code = get_language())
+
 
 class CommentDocument(DetailView):
     model = CommentDocument