Skip to content

Commit

Permalink
Merge pull request #34 from Elthan/bug-24
Browse files Browse the repository at this point in the history
Fixes #24
  • Loading branch information
torgeirl committed Jul 20, 2018
2 parents 2f6da6f + 1d7a321 commit 9a82518
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
13 changes: 11 additions & 2 deletions trix/trix_core/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django import forms
from django.contrib import admin
from django.contrib.auth.models import Group
from django.db.models import Count, Q
Expand Down Expand Up @@ -92,6 +93,14 @@ def queryset(self, request, queryset):
)


class TagAdminForm(forms.ModelForm):
def clean_tag(self):
tag = self.cleaned_data['tag']
tag = coremodels.Tag.split_commaseparated_tags(tag)
self.cleaned_data['tag'] = tag[0]
return self.cleaned_data['tag']


class TagAdmin(admin.ModelAdmin):
search_fields = ['tag']
list_display = [
Expand All @@ -101,6 +110,7 @@ class TagAdmin(admin.ModelAdmin):
'is_in_use'
]
list_filter = [TagInUseFilter]
form = TagAdminForm

def get_queryset(self, request):
return super(TagAdmin, self).get_queryset(request)\
Expand Down Expand Up @@ -128,7 +138,6 @@ class CourseAdmin(admin.ModelAdmin):
'course_tag',
'active_period',
'get_admins',

)
search_fields = [
'course_tag__tag',
Expand All @@ -139,7 +148,7 @@ class CourseAdmin(admin.ModelAdmin):
raw_id_fields = ['course_tag', 'active_period']

def get_admins(self, course):
return u','.join(unicode(user) for user in course.admins.all())
return u', '.join(unicode(user) for user in course.admins.all())
get_admins.short_description = 'Admins'

def get_queryset(self, request):
Expand Down
12 changes: 8 additions & 4 deletions trix/trix_core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,23 @@ class Course(models.Model):
null=False,
default='')

#: TODO: Limit choices to ``c``-tags
course_tag = models.ForeignKey(
Tag,
related_name='course_set',
on_delete=models.CASCADE)
on_delete=models.CASCADE,
limit_choices_to={
'category': 'c'
})

#: TODO: Limit choices to ``p``-tags
active_period = models.ForeignKey(
Tag,
related_name='active_period_set',
null=True,
blank=True,
on_delete=models.SET_NULL)
on_delete=models.SET_NULL,
limit_choices_to={
'category': 'p'
})

class Meta:
verbose_name = _('Course')
Expand Down

0 comments on commit 9a82518

Please sign in to comment.