0
moderationツールでブロックを追加することで、ビデオオブジェクトのdjango-adminの変更フォームをカスタマイズしたいと考えています。Djangoのシンプルタグが動作しない場合
if条件でカスタムシンプルタグを使用すると動作しません。
models.py:
class Video(models.Model):
class Meta:
db_table = 'video'
DRAFT = 1
MODERATION = 2
PUBLISHED = 3
REJECTED = 4
HOSTING_UPLOADING = 5
SUSPICIOUS = 6
PUBLICATION_STATUSES = (
(DRAFT, 'draft'),
(MODERATION, 'moderation'),
(PUBLISHED, 'published'),
(HOSTING_UPLOADING, 'hosting uploading'),
(REJECTED, 'rejected'),
(SUSPICIOUS, 'suspicious')
)
video_pk = models.AutoField(primary_key=True)
name = models.CharField(max_length=150, blank=True)
hosting_id = models.CharField(max_length=20, blank=True)
publication_status = models.PositiveSmallIntegerField(choices=PUBLICATION_STATUSES, default=MODERATION)
templatetagsのvideo_publication_statuses.py:
from api.models import Video
from django import template
register = template.Library()
@register.simple_tag
def moderation(status):
return status == Video.MODERATION
@register.simple_tag
def suspicious(status):
return status == Video.SUSPICIOUS
@register.simple_tag
def published(status):
return status == Video.PUBLISHED
@register.simple_tag
def hosting_uploading(status):
return status == Video.HOSTING_UPLOADING
@register.simple_tag
def rejected(status):
return status == Video.REJECTED
がchange_form.html:
{% extends "admin/change_form.html" %}
{% load video_publication_statuses %}
{% suspicious original.publication_status as suspicious_status %}
{% moderation original.publication_status as moderation_status %}
{% hosting_uploading original.publication_status as hosting_uploading_status %}
{% published original.publication_status as published_status %}
{% rejected original.publication_status as rejected_status %}
{% block after_related_objects %}
{% if original.pk %}
{% for fieldset in adminform %}
{% if fieldset.name == 'Moderation' %}
{% include "admin/includes/fieldset.html" %}
{% endif %}
{% endfor %}
<div class="submit-row">
{% if rejected_status or moderation_status or suspicious_status %}
<input type="submit" value="Publish" name="publish" >
{% endif %}
{% if published_status %}
<input type="submit" value="Reject" name="reject" >
{% endif %}
</div>
{% endif %}
{% endblock %}
私が代わりにタグの明示的な値を使用する場合、それは動作します:
を{% if original.publication_status == 3 %}
<input type="submit" value="Reject" name="reject" >
{% endif %}
タグの間違いを理解してもらえますか?