Changes between Initial Version and Version 1 of Ticket #15602, comment 19


Ignore:
Timestamp:
Jul 14, 2018, 12:54:23 PM (6 years ago)
Author:
John

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #15602, comment 19

    initial v1  
    2020class TransactionTabularInline(admin.TabularInline):
    2121        model = models.Transaction
    22         extra = 1
    23         max_num = 0
     22        extra = 1  # extra must be 1 to make the magic work
     23        max_num = 0  # somehow this disable the "add" because max_num > extra
    2424        fields = (contains only a handful of fields)
    2525        can_delete = False
    26         show_change_link = True
     26        show_change_link = True  # allow viewing the full entry in another page
    2727        readonly_fields = [
    2828                        the list of 'fields'
     
    3636        def get_queryset(self, request):
    3737                queryset = super().get_queryset(request)
    38                 return queryset.none()
     38                return queryset.none()  # no existing records will appears
    3939}}}
    4040
     
    4242
    4343I think you can use two (stacked) inlines, one for existing records with more `readonly_fields`, and one without readonly but return an empty query_set.
     44
     45I found `queryset.none()` from django's code, when users has no permission on the object.  So, I suppose this is "okay" when I do not want to display existing records for my own reason.
Back to Top