I’m a newbie. In my textbook there is this example:
from django.contrib import admin
from django.db import models
class BlogPost(models.Model):
title = models.CharField(max_length = 150)
body = models.TextField()
timestamp = models.DateTimeField()
class BlogPostAdmin(admin.ModelAdmin):
list_display = ('title', 'timestamp')
admin.site.register(BlogPost, BlogPostAdmin)
When I started playing with it, I discovered that I may use both tuples and lists here (either list_display = (‘title’, ‘timestamp’) or list_display = [‘title’, ‘timestamp’]).
Could you help me find in the documentation the answer to the question why this is possible?
That may help me elaborate some skills in working with the documentation.
I shouldn’t think it would be mentioned in the Django documentation. It’s trivial Python: in most cases, lists and tuples are equivalent, because the code is just expecting an iterable, which both of those are.
That’s probably the point you’re missing – it’s to do with duck typing, where as long as the object exposes the expected functionality (iterable in this case), you shouldn’t care what exact type it is.