• <small id='VPQOt'></small><noframes id='VPQOt'>

    <i id='VPQOt'><tr id='VPQOt'><dt id='VPQOt'><q id='VPQOt'><span id='VPQOt'><b id='VPQOt'><form id='VPQOt'><ins id='VPQOt'></ins><ul id='VPQOt'></ul><sub id='VPQOt'></sub></form><legend id='VPQOt'></legend><bdo id='VPQOt'><pre id='VPQOt'><center id='VPQOt'></center></pre></bdo></b><th id='VPQOt'></th></span></q></dt></tr></i><div id='VPQOt'><tfoot id='VPQOt'></tfoot><dl id='VPQOt'><fieldset id='VPQOt'></fieldset></dl></div>

        <tfoot id='VPQOt'></tfoot>

      1. <legend id='VPQOt'><style id='VPQOt'><dir id='VPQOt'><q id='VPQOt'></q></dir></style></legend>
        • <bdo id='VPQOt'></bdo><ul id='VPQOt'></ul>

        在admin django 1.6中注册抽象模型

        时间:2023-11-07
          <bdo id='X0kEa'></bdo><ul id='X0kEa'></ul>

                    <tbody id='X0kEa'></tbody>
                1. <legend id='X0kEa'><style id='X0kEa'><dir id='X0kEa'><q id='X0kEa'></q></dir></style></legend>

                  <i id='X0kEa'><tr id='X0kEa'><dt id='X0kEa'><q id='X0kEa'><span id='X0kEa'><b id='X0kEa'><form id='X0kEa'><ins id='X0kEa'></ins><ul id='X0kEa'></ul><sub id='X0kEa'></sub></form><legend id='X0kEa'></legend><bdo id='X0kEa'><pre id='X0kEa'><center id='X0kEa'></center></pre></bdo></b><th id='X0kEa'></th></span></q></dt></tr></i><div id='X0kEa'><tfoot id='X0kEa'></tfoot><dl id='X0kEa'><fieldset id='X0kEa'></fieldset></dl></div>
                2. <tfoot id='X0kEa'></tfoot>

                3. <small id='X0kEa'></small><noframes id='X0kEa'>

                  本文介绍了在admin django 1.6中注册抽象模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  搜索了一段时间后,我没有找到任何明确的解决方案

                  After searching a while i didn't find any clear solution

                  文件:models.py

                  class BaseModel(models.Model):
                      created_date = models.DateTimeField(auto_now_add=True)
                      modified_date = models.DateTimeField(auto_now=True)
                  
                      class Meta:
                          abstract = True
                  
                  
                  class Company(BaseModel):
                      company_name = models.CharField(max_length=50, unique=True)
                  
                      def __str__(self):
                          return self.company_name
                  

                  文件:models.py

                  from django.contrib import admin
                  from .models import Company
                  
                  class CompanyAdmin(admin.ModelAdmin):
                      pass
                  
                  admin.site.register(Company, CompanyAdmin)
                  

                  我在这里尝试了解决方案:Django admin model Inheritance is可能吗? 但没有任何效果,管理员只显示公司名称

                  I tried the solution here: Django admin model Inheritance is it possible? but nothing works, and the admin is only showing the company_name

                  推荐答案

                  这些字段没有显示在后台的原因是 auto_nowauto_now.您需要做的是将它们显式添加为只读字段:

                  The reason why those fields are not being showed in the admin, is because of the auto_now and auto_now. What you need to do is adde them explicitly as read-only fields:

                  admin.py

                  from django.contrib import admin
                  from .models import Company
                  
                  class CompanyAdmin(admin.ModelAdmin):
                      readonly_fields = ('created_date', 'modified_date')
                  
                  admin.site.register(Company, CompanyAdmin)
                  

                  这篇关于在admin django 1.6中注册抽象模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 Django Admin 中使用内联 OneToOneField 下一篇:django-admin 中的动态表单

                  相关文章

                  <legend id='Mp0DV'><style id='Mp0DV'><dir id='Mp0DV'><q id='Mp0DV'></q></dir></style></legend>

                      <bdo id='Mp0DV'></bdo><ul id='Mp0DV'></ul>

                    <small id='Mp0DV'></small><noframes id='Mp0DV'>

                    <tfoot id='Mp0DV'></tfoot>

                    1. <i id='Mp0DV'><tr id='Mp0DV'><dt id='Mp0DV'><q id='Mp0DV'><span id='Mp0DV'><b id='Mp0DV'><form id='Mp0DV'><ins id='Mp0DV'></ins><ul id='Mp0DV'></ul><sub id='Mp0DV'></sub></form><legend id='Mp0DV'></legend><bdo id='Mp0DV'><pre id='Mp0DV'><center id='Mp0DV'></center></pre></bdo></b><th id='Mp0DV'></th></span></q></dt></tr></i><div id='Mp0DV'><tfoot id='Mp0DV'></tfoot><dl id='Mp0DV'><fieldset id='Mp0DV'></fieldset></dl></div>