我最近将一个应用程序添加到了Django Web应用程序中。我对正在发生的问题感到困惑。当我将下面的admin.py文件添加到应用程序并部署代码时,响应时间在站点的多个区域中增加,而许多区域无关。 ModelAdmin的编写方式有问题吗?有人经历过吗?我正在运行Django 1.11。
admin.py:
class SubscriberAdmin(admin.ModelAdmin):
list_display = ('email',)
fields = ('email', 'verified')
readonly_fields = ('email', 'verified')
list_per_page = 50
admin.site.register(Subscriber, SubscriberAdmin)
models.py:
class Subscriber(models.Model):
email = models.EmailField(null=False, unique=True)
activation_key = models.CharField(max_length=64)
key_expires = models.DateTimeField(default=get_key_expiration)
verified = models.BooleanField(default=False)
agency_class = {}
agency_type = None
@classmethod
def send_notifications(cls, agency_type, slugs):
"""
Sends notification emails to all subscribers.
:param agency_type: 'salary' or 'pension'
:param slugs: [list of agency slugs]
"""
cls._set_agency_type(agency_type)
subscribers = cls.objects.all()
for subscriber in subscribers:
subscriber._send_notification(slugs)
def _send_notification(self, slugs):
# code removed for brevity
答案 0 :(得分:0)
问题可能出在get_key_expiration。也许每次创建对象订户并且函数运行缓慢时都会调用该函数吗?