I should have spent the extra 10 minutes trying out the 'property' solution (rather than the several hours I've spent on the generic view/ pagination code).
Adding this code to the model works perfectly well. def _link(self): from settings import ACCESS_PATH if self.mimetype == 'url': return '%sredirect?location=%s' % (ACCESS_PATH, self.uuid) else: return '%sdownload/%s/%s' % (ACCESS_PATH, self.uuid, self.filename) link = property(_link) I wouldn't mind, except I've used properties extensively before and it never occurred to me to use them this time .... sigh. Cheers, Tone On Mar 30, 12:38 pm, tonemcd <tony.mcdon...@gmail.com> wrote: > Hi, > I'm used to doing things like this; > > resources = Resource.objects.all() > for resource in resources: > if resource.thetype == 'url': > resource.link = '/access/redirect?location=%s' % resource.uuid > else: > resource.link = '/access/download/%s/%s' % (resource.uuid, > resource.filename) > > It means that more logic is shunted from the template to the view. > > This helps some browsers to determine what they should do with a link > (we use file-disposition and mimetype etc - but we still need to do > this) > > I've just wired this up to generic views and find that this line (46) > in django/views/generic/list_detail.py causes the 'link' attribute to > disappear. (I put 'queryset[0].__dict__' before and after the line and > 'link' had dissappeared) > > 46: queryset = queryset._clone() > > Is this expected behaviour? If so, should I be doing things in a > different way (property on the model perhaps)? > > Any thoughts appreciated > Cheers, > Tone --~--~---------~--~----~------------~-------~--~----~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---