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

        <bdo id='9Ereo'></bdo><ul id='9Ereo'></ul>

      <tfoot id='9Ereo'></tfoot>

      1. <legend id='9Ereo'><style id='9Ereo'><dir id='9Ereo'><q id='9Ereo'></q></dir></style></legend>

      2. Django Admin 的内联解决方案,其中 Admin 包含其他模型的 ForeignKey

        Inline-like solution for Django Admin where Admin contains ForeignKey to other model(Django Admin 的内联解决方案,其中 Admin 包含其他模型的 ForeignKey)
          <tbody id='TuIoL'></tbody>

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

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

                <tfoot id='TuIoL'></tfoot>

                • 本文介绍了Django Admin 的内联解决方案,其中 Admin 包含其他模型的 ForeignKey的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有几个 Customer 预订 Appointment.每个 Appointment 都只有一位客户,但可以为一位客户预订在不同时间发生的多个约会.

                  I have several Customers who book Appointments. Each Appointment has exactly one customer, though a customer can be booked for multiple appointments occurring at different times.

                  class Customer(model.Model):
                      def __unicode__(self):
                          return u'%s' % (self.name,)
                      name = models.CharField(max_length=30)
                      # and about ten other fields I'd like to see from the admin view.
                  
                  class Appointment(models.Model):
                      datetime = models.DateTimeField()
                      customer = models.ForeignKey("Customer")
                      class Meta:
                          ordering = ('datetime',)
                  

                  现在,当管理员通过查看管理员中的约会(按时间排序)来浏览日程时,有时他们希望查看有关具有特定约会的客户的信息.现在,他们必须记住客户的姓名,从约会导航到客户管理页面,找到记住的客户,然后才能浏览他们的信息.

                  Now when an admin goes to browse through the schedule by looking at the Appointments (ordered by time) in the admin, sometimes they want to see information about the customer who has a certain appointment. Right now, they'd have to remember the customer's name, navigate from the Appointment to the Customer admin page, find the remembered Customer, and only then could browse their information.

                  理想情况下,像管理员内联这样的东西会很棒.但是,如果 Customer 有一个 ForeignKey("Appointment")<,我似乎只能在 Appointment 管理页面上创建一个 CustomerInline/代码>.(Django 专门给了我一个错误,说 Customer has no ForeignKey to Appointment).有谁知道类似的功能,但是当 AppointmentForeignKey('Customer') 时?

                  Ideally something like an admin inline would be great. However, I can only seem to make a CustomerInline on the Appointment admin page if Customer had a ForeignKey("Appointment"). (Django specifically gives me an error saying Customer has no ForeignKey to Appointment). Does anyone know of a similar functionality, but when Appointment has a ForeignKey('Customer')?

                  注意:我简化了模型;实际的客户字段目前除了名称(一些自由文本)之外大约有 10 个字段,因此将所有信息放在 __unicode__ 中是不切实际的.

                  Note: I simplified the models; the actual Customer field currently has about ~10 fields besides the name (some free text), so it would be impractical to put all the information in the __unicode__.

                  推荐答案

                  完成@John的从上面回答 - 定义您希望在更改列表中看到的内容:

                  Completing @John's answer from above - define what you would like to see on the your changelist:

                  return '<a href="%s">%s</a>' % (
                                       reverse('admin:applabel_customer_change', (self.customer.id,)),
                                       self.customer.name # add more stuff here
                               )
                  

                  要将其添加到更改表单中,请参阅:在 Django 管理员的 change_form 中的两个模型字段之间添加自定义 html

                  And to add this to the change form, see: Add custom html between two model fields in Django admin's change_form

                  这篇关于Django Admin 的内联解决方案,其中 Admin 包含其他模型的 ForeignKey的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                  How to extend Python class init(如何扩展 Python 类初始化)
                  What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                  What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                  Initialize list with same bool value(使用相同的布尔值初始化列表)
                  setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)

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

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

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

                      <tfoot id='wugaV'></tfoot>

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

                            <tbody id='wugaV'></tbody>