I have seen fields in the django-rest-framework initialized/declared with parentheses ()
and brackets []
and I am wondering if there is a difference.
I have only been using () but I see [] in the documentation everywhere.
Say we have a model Dog.
class Dog(models.Model):
favorite_food = models.CharField(max_length=255)
Now would it be correct to say that these two serializers below for this Dog model are the same? Even though the field
is declared with different ASCII characters.
class DogSerializer(serializers.ModelSerializer):
class Meta:
model = Dog
fields = ('id', 'favorite_food')
class DogSerializer(serializers.ModelSerializer):
class Meta:
model = Dog
fields = ['id', 'favorite_food']