Django: Managing urls like id:slug with duplicated slug -


using django 1.5 storing slug in db

i configured urls follows:

url(r'^(?p<id>[0-9]+):(?p<slug>[-\w]+)$', tracksdetailview.as_view(), name="track-view"), 

and in podel have:

@models.permalink def get_absolute_url(self):     return ('track-view', [str(self.id), str(self.slug)]) 

if 2 slugs same following error:

get() returned more 1 gpxtrack -- returned 2! lookup parameters {} 

i use generic view (detailview) render page:

class tracksdetailview(detailview):     model = gpxtrack     context_object_name = 'track' 

any idea on how avoid without needing unique slugs?

you going have override view's get_object method. 1 you're inheriting not take account you're using id , slug. assumes you're passing either pk or slug - , assumes they're unique.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -