From: Aleksander Ɓukasz Date: Wed, 16 Oct 2013 10:40:18 +0000 (+0200) Subject: Filter comment documents by current language X-Git-Url: https://git.mdrn.pl/edumed.git/commitdiff_plain/d1340b5e0beeede44a20a09d6c9f103db6dee9c4 Filter comment documents by current language --- 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 index 0000000..686f568 --- /dev/null +++ b/comment/migrations/0002_auto__add_field_commentdocument_language_code.py @@ -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 diff --git a/comment/models.py b/comment/models.py index a5c3000..4cbabfa 100644 --- a/comment/models.py +++ b/comment/models.py @@ -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'] diff --git a/comment/views.py b/comment/views.py index 748f9c4..e494828 100644 --- a/comment/views.py +++ b/comment/views.py @@ -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