2017-05-08 22 views
1

我想问一下在这段代码中使用._meta吗?我没有发现,解释了如何使用.META使用._meta Django

def resend_activation_email(self, request, queryset): 
    """ 
    Re-sends activation emails for the selected users. 

    Note that this will *only* send activation emails for users 
    who are eligible to activate; emails will not be sent to users 
    whose activation keys have expired or who have already 
    activated. 

    """ 
    if Site._meta.installed: 
     site = Site.objects.get_current() 
    else: 
     site = RequestSite(request) 

    for profile in queryset: 
     if not profile.activation_key_expired(): 
      profile.send_activation_email(site) 
resend_activation_email.short_description = _("Re-send activation emails") 

回答

1

_meta的顾名思义存储模型的元数据的文档。说,你想循环模型的所有领域,那么你可以使用model._meta.get_fields()

顺便说一句,荟萃选项覆盖在文档中 -

Model Meta options documentation

+0

谢谢很多 – Faraha

+0

请将其标记为正确的答案,如果它帮助。 – hspandher

相关问题