'ImproperlyConfigured: There are duplicate field(s) in PackageAdmin.fieldsets

I have a very simple model :

   class Package(models.Model):
    package_id = models.IntegerField()
    package_name = models.CharField(max_length=20)
    subscriptions = models.ManyToManyField('Subscription', blank=True, null=True)

here is the admin.py :

from django.contrib import admin
from auth.models import Subscription, Package

class PackageAdmin(admin.ModelAdmin):
    list_display = ('package_name', 'package_id')
    fieldsets = (
       (None, {
           'fields': ('package_name')
           }),
       ('Advanced options', {
           'fields': ('package_id')
           }),
    )

admin.site.register(Package, PackageAdmin)

This implementation give me the following error :

ImproperlyConfigured: There are duplicate field(s) in PackageAdmin.fieldsets

Any idea why ?

If I let the second 'fields' empty, I don't get the error. But if I let the first 'fields' empty, I still have this error.



Solution 1:[1]

from django.contrib import admin
from auth.models import Subscription, Package

class PackageAdmin(admin.ModelAdmin):
    list_display = ('package_name', 'package_id')
    fieldsets = (
       (None, {
           'fields': ('package_name',)
           }),
       ('Advanced options', {
           'fields': ('package_id',)
           }),
    )

admin.site.register(Package, PackageAdmin)

you must insert a comma at the end of each field

Solution 2:[2]

A tuple with only one value needs a comma "," at the end of it.

So, you need to add a comma "," to the end of each tuple in your code as shown below:

'fields': ('package_name',)
                         ? Here
'fields': ('package_id',)
                       ? Here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 CRISTIAN CANO PALOMAR
Solution 2 Kai - Kazuya Ito