views:

152

answers:

2

Hi. I have an inline formset in my admin site. I also have save_as = True in admin.py. My models are, for example:

class Poll(models.Model):
    question = models.CharField(max_length=200, unique = True)
    pub_date = models.DateTimeField('date published')

class Choice(models.Model):
    poll = models.ForeignKey(Poll)
    choice = models.CharField(max_length=200)
    votes = models.IntegerField()

I chose to have an unique question. The problem is, whenever I try to save a poll as a new poll, if I forget to change the question I get an error, as it supposed to happen. But if I then change the question and try to save I get this error: invalid literal for int() with base 10: '' and if I check the error I see that the pool foreign key is not available and that's the cause of the error. Anyone else has got this error? Is it a django bug? I know that there was an error related with save_as in http://code.djangoproject.com/ticket/9651 but I can't tell if it's related with my error. Try in the django tutorial as I did and see if the error appears. Thanks for any reply.

A: 

I've never had much luck with Save as and relationships. Although, I think I was trying to do complicated many to many stuff.

What is the url of the page that is giving that error... From the errors it looks like it would be something like.... /admin/myapp/poll// whereas it should be something more like /admin/myapp/poll/103/. So the error is caused by the admin's urls parsing trying to convert the PK of '' to an int so it can look it up in the DB.

You'll get that error whenever you have a admin url that has an ID that is not an int (and your PK field is an int). It was probably None (because it didn't save) and then the admin tried to redirect it there.

Bug in Django? Could be, but I doubt it - Django is pretty stable these days. But you never know.

Humphrey
A: 

I just had this error with a different part of the tutorial. I don't know about the admin part, but have you checked your templates for typos? I had a template that was supposed to pass choice_id and instead I was passing choice_if which was nonsense. Just a thought.

An Idiot