I installed Django for the first time yesterday and trying it out in earnest today. I’m only planning to use it for the beautiful admin interface, Zend Framework for the rest.
I imported an existing table event into the admin. There’s no join needed. But the primary key is not ‘id’ it’s called “event” (following this naming convention). I obviously don’t want this column’s id# to appear in the data entry form.
Everything works fine, EXCEPT when adding a new event, I click Save and Continue Editing, it adds the event, but redirects the URL to
http://127.0.0.1:8000/admin/events/event/None/
and spits out this error
ValueError at /admin/events/event/None/
invalid literal for int() with base 10: 'None'
This is my models.py:
from django.db import models
class Event(models.Model):
event = models.IntegerField(primary_key=True)
title = models.CharField(max_length=150)
address_1 = models.CharField(max_length=150)
url = models.URLField(max_length=500,verify_exists=False)
start_date = models.DateField()
end_date = models.DateField()
ACTIVE_CHOICES = (
(0, 'InActive'),
(1, 'Active'),
)
active = models.CharField(max_length=1, default=1, choices=ACTIVE_CHOICES)
def __unicode__(self):
return self.title
class Meta:
db_table = u'event'
Any ideas what I’m doing wrong or how to fix this?
You probably want the PK to be an
AutoFieldinstead of anIntegerFieldso Django will automatically fill it in for you. Otherwise you have to do it yourself in the save method or the admin interface: