added is_pushed and some "styling"
This commit is contained in:
@@ -28,8 +28,9 @@ class LabelAdmin(PermissionsAdminMixin, admin.ModelAdmin):
|
||||
@admin.register(Question)
|
||||
class QuestionAdmin(PermissionsAdminMixin, admin.ModelAdmin):
|
||||
autocomplete_fields = ('medias', 'links', 'labels', 'shares')
|
||||
list_display = ('name', 'list_labels', 'list_level', 'author')
|
||||
list_display = ('name', 'list_labels', 'list_level', 'author', 'is_published')
|
||||
search_fields = ('name', 'question', 'awnser', 'description', 'label__name', 'level__value', 'level__name',)
|
||||
list_editable = ('is_published',)
|
||||
|
||||
def list_labels(self, instance):
|
||||
if instance.labels:
|
||||
|
||||
@@ -11,7 +11,7 @@ from django.utils.safestring import mark_safe
|
||||
from filer.fields.file import FilerFileField
|
||||
|
||||
from lib.core.db.models.base import SharedPermissionBase
|
||||
from lib.core.db.models.mixins import DateAware, AuthorAware, DescriptionAware, NameAware
|
||||
from lib.core.db.models.mixins import DateAware, AuthorAware, DescriptionAware, NameAware, PublishedAware
|
||||
|
||||
|
||||
class MediaFile(NameAware, DateAware, AuthorAware, DescriptionAware):
|
||||
@@ -62,7 +62,7 @@ class SharedQuestion(SharedPermissionBase):
|
||||
abstract = False
|
||||
|
||||
|
||||
class Question(DateAware, AuthorAware, DescriptionAware):
|
||||
class Question(DateAware, AuthorAware, PublishedAware, DescriptionAware):
|
||||
name = models.CharField(max_length=500, unique=True, db_index=True)
|
||||
question = models.TextField(db_index=True)
|
||||
buzzword = models.CharField(max_length=25, null=True, blank=True)
|
||||
@@ -90,8 +90,10 @@ class Question(DateAware, AuthorAware, DescriptionAware):
|
||||
|
||||
|
||||
@staticmethod
|
||||
def get_by_tearchterm(term):
|
||||
return Question.objects.filter(Question.searchdomain(term)).annotate(cnt=models.Count('id'))
|
||||
def get_by_tearchterm(term, queryset=None):
|
||||
if not queryset:
|
||||
queryset = Question.objects
|
||||
return queryset.filter(Question.searchdomain(term)).annotate(cnt=models.Count('id'))
|
||||
|
||||
|
||||
def to_view(self, for_players: bool = False):
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
{% block content %}
|
||||
<form action="/questions" method="get" id="search_q_form">
|
||||
<div id="question-search-field" class="row mb-5 mt-5">
|
||||
<div class="col-12">
|
||||
<div class="form-group">
|
||||
<div class="col-12 p-0">
|
||||
<div class="form-group border rounded p-3 bg-secondary">
|
||||
<div class="input-group">
|
||||
{% csrf_token %}
|
||||
{# {% csrf_token %} #}
|
||||
<input type="text" name="term" class="form-control p-2 bg-light" placeholder="Search for ..." value="{{ request.GET.term }}" />
|
||||
<span class="input-group-text">
|
||||
<i class="fa fa-search" onclick="document.getElementById('search_q_form').submit();"></i>
|
||||
|
||||
@@ -3,4 +3,5 @@ from content.views import public
|
||||
|
||||
urlpatterns = [
|
||||
path('questions/', public.search_question, name='search-questions'),
|
||||
path('', public.search_question, name='search-questions'),
|
||||
]
|
||||
|
||||
@@ -6,8 +6,9 @@ from content.models import Question
|
||||
def search_question(request):
|
||||
term = request.GET.get('term')
|
||||
items = []
|
||||
published = Question.objects.filter(is_published=True)
|
||||
if term:
|
||||
items = Question.get_by_tearchterm(term)
|
||||
items = Question.get_by_tearchterm(term, published)
|
||||
else:
|
||||
items = Question.objects.all()[:10]
|
||||
items = published.all()[:10]
|
||||
return render(request, 'questions.html', {'items': items})
|
||||
|
||||
Reference in New Issue
Block a user