Django不会在标签中打印数据

时间:2016-07-27 10:53:57

标签: django

在我的admin.py中,我试图从数据库输出数据。然而,我遇到的问题是它输出如下:

[,]

进一步检查后,数据就在那里,但它只是用标签包装

<div class="grp-readonly">[<slot: c10980="" ,="" #4182="" 2017-01-01="" 13:00:00+00:00="" -="" 14:00:00="">, <slot: c10966="" ,="" #4169="" 2017-01-01="" 13:00:00+00:00="" -="" 14:00:00="">]</slot:></slot:></div>

由于某种原因,它似乎将其包装在插槽标记中。请注意,这不是一个模板,只是在admin.py文件中完成,数据来自models.py.

我想要它以便打印出数据。

我已经看过allow_tags了,或者我没有正确实现它,或者它不是正确的工作。

非常感谢任何帮助。

编辑:编辑添加python代码:

Admin.py:

@add_link_field()
class SlotAdminInline(admin.TabularInline):
model = Slot
extra = 1
fields = (('is_unique', 'start', 'end', 'status',),
          ('locations', ),
          ('activity_support', 'type',  'actual_time', 'get_overlapping_slots'))
readonly_fields = ('is_unique', 'get_overlapping_slots')
template = "admin/edit_inline/tabular.html"
form = SlotAdminForm

formfield_overrides = {
    models.ManyToManyField: {'widget': CheckboxSelectMultiple},
}

def queryset(self, request):
    qs = super(SlotAdminInline, self).get_queryset(request).order_by('start', 'end')
    return qs

def get_readonly_fields(self, request, obj=None):
    if not request.user.has_perm('booking.can_use_full_booking_form'):
        fields = self.readonly_fields

        if self.declared_fieldsets:
            fields = flatten_fieldsets(self.declared_fieldsets)
        else:
            fields = list(set(
                [field.name for field in self.opts.local_fields] +
                [field.name for field in self.opts.local_many_to_many]
            ))
    else:
        if self.readonly_fields:
            fields = self.readonly_fields

    return fields

Models.py

def get_overlapping_slots(self):

    start_datetime = self.start
    end_datetime = datetime.combine(self.start.date(), self.end)

    print start_datetime
    print end_datetime

    #localtz = pytztimezone('Europe/Lisbon')
    #end_datetime = localtz.localize(tzinfo=pytz.UTC)

    end_datetime = end_datetime.replace(tzinfo=pytz.UTC)

    print start_datetime, end_datetime

    # filter based on the locations initially
    qs = self.__class__._default_manager.filter(
        locations__in=self.locations.all()
    )

    # next exclude this slot from the query set
    qs = qs.exclude(pk=self.pk)

    qs = qs.filter(start__range=(datetime.combine(start_datetime.date(), time.min),
                        datetime.combine(start_datetime.date(), time.max)))

    # next exclude cancelled slots from the query set
    #qs = qs.exclude(pk=BookingStatus.cancelled)
    #qs = qs.exclude(pk=SessionStatus.cancelled)



    # finally find overlapping sessions based on the time
    qs = qs.filter(
        start__lt=end_datetime,
        end__gt=start_datetime
    )

    return qs

0 个答案:

没有答案