Django object.id does not match with the objects used in reverse url look up -


i have model "listing" represents companies, model "lead" represents different projects can assigned companies. associated via many many relationship since company can assigned many leads many leads can associated many other companies. models listed below.

leads displayed in listing admin page inline elements. there snippet used display link directly lead edit page of object done through reverse url.

problem object.id argument wrong not corresponding leads id other number.

enter image description here

in image above lead id shown "53".but in reality 78. pointers may missing appreciated.

enter image description here

#admin.py     def url_to_edit_object(self,object):                     #info = (object._meta.app_label, object._meta.module_name)                     admin_url = reverse('admin:dirapp_lead_change',  args=(object.id,))                     return u'<a href="%s">edit</a>' %(admin_url) 

lead model:

class lead(models.model):     slug = models.slugfield(unique=true,blank=true, null=true)     first_name = models.charfield(max_length=100)     last_name = models.charfield(max_length=100, blank=true, null=true)     business_name = models.charfield(max_length=100,blank=true, null=true)     email = models.emailfield(max_length=75, blank=true, null=true)     phone_number = models.charfield(max_length=20, blank=true, null=true)     address = models.charfield(max_length=150, blank=true, null=true)     city = models.charfield(max_length=50, blank=true, null=true)     state = models.charfield(max_length=10, blank=true, null=true)     zipcode = models.charfield(max_length=5, blank=true, null=true)     submission_date = models.datetimefield(auto_now_add=true, blank=true)     assigned_to = models.manytomanyfield(listing,blank=true, null=true, related_name="leads")     requested_software = models.charfield(max_length=50, blank=true, null=true)     number_of_pos = models.charfield(max_length=2, choices=no_of_pos, default='1')     type_of_business = models.charfield(max_length=30, choices=type_of_business, default='bar nightclub', blank=true, null=true)     time_frame = models.charfield(max_length=10, choices=time_frame, default='1')     comments = models.textfield(blank=true, null=true)      def __unicode__(self):         return self.business_name     @models.permalink     def get_absolute_url(self):         return ('listing_detail', (),                     {                         'slug' :self.slug,                         })      def save(self, *args, **kwargs):         if not self.slug:             self.slug = slugify(self.business_name)             super(lead, self).save(*args, **kwargs) 

listing model:

class listing(models.model):         """         base model listings           """         status_choices = (         ('a', 'active'),         ('p', 'pending'),         )         status = models.charfield(max_length=1, choices=status_choices, default='p')         slug = models.slugfield(unique=true,blank=true, null=true)         submitted_by = models.manytomanyfield(user, blank=true, null=true, related_name="associates")         title = models.charfield(max_length=120, blank=true, null=true)         point = models.pointfield(geography=true,srid=settings.srid, blank=true, null=true)         point2 = models.charfield(max_length=120, blank=true, null=true)         address = models.charfield(max_length=120, blank=true, null=true)         city = models.charfield(max_length=60, blank=true, null=true)         state = models.charfield(max_length=60, blank=true, null=true)         zipcode = models.charfield(max_length=5, blank=true, null=true)         industry = models.manytomanyfield(indcat, related_name="category", blank=true, null=true)         description = models.textfield(blank=true, null=true)         objects = models.geomanager()         tags = taggablemanager(blank=true)         search = sphinxsearch()          def __unicode__(self):                 #return "%s %s %s"%(self.title, self.point.x, self.point.y)                 return "%s"%(self.title)         @models.permalink         def get_absolute_url(self):                 return ('listing_detail', (),                     {                         'slug' :self.slug,                         })          def save(self, *args, **kwargs):                 if not self.slug:                         self.slug = slugify(self.title)                 if not self.point:                         location = "%s+%s+%s+%s"%(self.address, self.city, self.state, self.zipcode)                         cord = get_lat_long(location)                         #x,y = cord.split(",")                         lat = float(cord[0])                         lng = float(cord[1])                         #x = float(lat)                         #y = float(lng)                          self.point = point(lng,lat)                         self.point2 = point(lng,lat)                 super(listing, self).save(*args, **kwargs) 

dirapp admin.py:

class listingimageinline(admin.stackedinline):     model = listingimage    class assignedleads(admin.tabularinline):         model = lead.assigned_to.through          = 0         #list_select_related = true         def url_to_edit_object(self,object):                 #info = (object._meta.app_label, object._meta.module_name)                 admin_url = reverse('admin:dirapp_lead_change',  args=(object.id,))                 return u'<a href="%s">edit</a>' %(admin_url)         url_to_edit_object.allow_tags = true         list_display = ('business_name','url_to_edit_object',)         readonly_fields = ('url_to_edit_object',)        class leadadmin(admin.modeladmin):     list_editable = ('city', 'state')     list_display = ('business_name','first_name','last_name','city','state','submission_date')     list_filter = ('city', 'state','submission_date', 'assigned_to')     inlines = [leadupdateinline]     filter_horizontal = ('assigned_to',)  class listingadmin(admin.modeladmin):     prepopulated_fields = {"slug":("title",)}     inlines = [leadupdateinline,listingimageinline, assignedleads]     filter_horizontal = ('submitted_by',)     class media:         js = (settings.static_url+'tinymce/jscripts/tiny_mce/tiny_mce.js',                  settings.static_url+"filebrowser/js/tinymceadmin.js",                  settings.static_url+"tinymce/jscripts/tiny_mce/tinymce_setup.js")   class emailreminderadmin(admin.modeladmin):         list_filter = ('lead', 'company','email_date_time')  admin.site.register(lead,leadadmin) admin.site.register(listing,listingadmin) admin.site.register(indcat) admin.site.register(email_reminder, emailreminderadmin) 

in url_to_edit_object method, object not lead instance - it's instance of intermediate model stores many many data.

use object.lead_id instead.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -