Nick Dong
Nick Dong

Reputation: 3736

does not have exactly two elements

I am starting python and django. I want to make and "add" page for adding data to sqlite3.

1. #my admin.py file
2. from django.contrib import admin
3. from jobs.models import Location
4. from jobs.models import Job
5. 
6. class JobAdmin(admin.ModelAdmin):
7.     fieldsets = [(None, {'fields': ['pub_date']},
8.                         {'fields': ['job_title']},
9.                         {'fields': ['job_description']},)
10. #       ('More info',  {'fields': ['location']},)
12.    ]
13. 
14. class LocationAdmin(admin.ModelAdmin):
15.     list_display = ('city', 'state', 'country')
16. 
17. admin.site.register(Job,JobAdmin)
18. admin.site.register(Location, LocationAdmin)

if I uncomment line 10, there is error.

Exception Type:      TypeError
Exception Value:     'tuple' object is not callable
Exception Location:  /home/python/djproject/jobs/admin.py in JobAdmin, line 10

if i comment line 10, like above, there is error.

Exception Type:     ImproperlyConfigured
Exception Value:    'JobAdmin.fieldsets[0]' does not have exactly two elements.
Exception Location: /usr/lib/python2.6/site-packages/django/contrib/admin/validation.py in validate_base, line 291

fields 'location' is a foreign key. there is no data in fields of Job in database, and I want to create an add page to insert data to database. and my models.py is:

#my models.py
from django.db import models

class Location(models.Model):
    city = models.CharField(max_length=50)
    state = models.CharField(max_length=50, null=True, blank=True)
    country = models.CharField(max_length=50)

    def __str__(self):
        if self.state:
            return "%s, %s, %s" % (self.city, self.state, self.country)
        else:
            return "%s, %s" % (self.city, self.country)

class Job(models.Model):
    pub_date = models.DateField()
    job_title = models.CharField(max_length=50)
    job_description = models.TextField()
    location = models.ForeignKey(Location)

    def __str__(self):
        return "%s (%s)" % (self.job_title, self.location)

I dont know how to do, can any one give me some references or advices? thx for ur time.

Upvotes: 0

Views: 164

Answers (2)

Rohan
Rohan

Reputation: 53386

There is missing ',' (comma) at the end of line # 9.

Upvotes: 1

Vivek S
Vivek S

Reputation: 5550

If you need to un comment the line, then you need to add a comma , before the line.

class JobAdmin(admin.ModelAdmin):
 fieldsets = [(None, {'fields': ['pub_date']},
                     {'fields': ['job_title']},
                     {'fields': ['job_description']},),
    ('More info',  {'fields': ['location']},)
]

Upvotes: 1

Related Questions