Saturday, May 19, 2012

Re: admin error, cannot edit fields or delete records, url refers to incorrect primary key

Problem solved. I had a double defined as my primary key in the mysql db. 

On Fri, May 18, 2012 at 10:49 PM, Mac <mmack3540@gmail.com> wrote:
I've set up a 'Reps' model in the admin. I can add records
successfully, but if I try to change a record or field, I get a 404
error. When I try to delete a record, I get this traceback here:
http://dpaste.com/750121/
My primary keys are integers, but it appears that the urls return them
as floats. Please see the example below.

The model in whl.models is as follows:

class Reps(models.Model):
   prim = models.AutoField(primary_key=True, db_column='PRIM')
   custno = models.CharField(max_length=50, db_column='CUSTNO',
blank=True) # Field name made .
   company = models.CharField(max_length=50, db_column='COMPANY',
blank=True)# Field name made
   #etc, etc.

   class Meta:
       db_table = u'whl_reps'
   def __unicode__(self):
       return self.custno + " : " + str(self.company)+" :
"+str(self.city)+" : "+str(self.state)
   def get_absolute_url(self):
       return "/%i/" % self.prim

My admin.py is:

from whl.models import Reps

class RepAdmin(admin.ModelAdmin):
   fields = ('company', 'email',  'salesmn',  'city',  'state')

And for example when I click on a record to change it, I get a 404
error with a message "reps object with primary key u'39.0' does not
exist". In this case, when i click on a record, it returns this url

localhost/admin/whl/reps/39.0/

As you can see, the last primary key above is not an integer as it
should be. When I manually change the url to /admin/whl/reps/39/ I can
edit the record.

I'm using Django 1.4, mysql db on Ubuntu.

Any thoughts on why this is happening? Any help would be appreciated
very much. Thanks.



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate