私の質問は、このスレッド [Question]http://stackoverflow.com/questions/851636/default-filter-in-django-admin の単なる拡張です。
from myproject.myapp.mymodels import fieldC
class Poll(models.Model):
fieldA = models.CharField(max_length=80, choices=CHOICES.MyCHOICES)
fieldB = models.ForeignKey(fieldC)
admin.py
list_display = ('fieldB__fieldc1')
Now my list filter shows four criteria All, A ,B ,C .
私が望むのは、スーパーユーザーがログインしている場合、フィルターは4つの基準すべて、A、B、Cを表示する必要があり、ユーザーがスーパーユーザーフィルター以外の場合、すべて、A、Bのみを表示する必要があることです.
どうすればこれを達成できますか? これがadmin.pyの実際の部分です
def changelist_view(self, request, extra_context=None):
referer = request.META.get('HTTP_REFERER', '')
test = referer.split(request.META['PATH_INFO'])
if test[-1] and not test[-1].startswith('?'):
if not request.GET.has_key('patient__patient_type__exact'):
q = request.GET.copy()
q['patient__patient_type__exact'] = 'Real'
request.GET = q
request.META['QUERY_STRING'] = request.GET.urlencode()
if not request.user.is_superuser:
q['patient__patient_type__exact'] = 'Real'
return super(VisitAdmin, self).changelist_view(request, extra_context)
Thanks in advance