Saturday, April 20, 2013

Re: defining guid, permalink for feeds and site

Yes that is a great idea.

create a base model that inherits from models.Model

add the method into it.

Any model that can be slugified and access directly should inherit from this

Make sure to use model.pk in building the slug, it will always be the primary key, rather than model.id which could change model to model

If you want to get all the child relationships permalinks then all you have to do is recurse through the managers calling the func.

All in all i think you have the right frame of mind so this isnt real an asnwer rather more of a +1


On Saturday, April 20, 2013 10:41:26 AM UTC-4, surya wrote:
In our website, for short urls we are using a different domain name.. 

So, get_absolute_url() in model methods uses django.core.urlresolvers.reserve() and thus returns the actual domain name

Till now we have been manually defining short urls in views like

permalink = settings.SPC['short_URL_root'] + str(submission.id) + '/' + \
                                                  str(revision.rev_id+1) + '/'

settings.SPC['short_url_root'] is short-url domain name

Since I feel this method inconsistent I would like to define a model method like below

from django.conf import settings
def permalink(self):
        return settings.SPC['short_URL_root'] + '/%d/%s' %(self.entry.pk, self.rev_id+1)

Would it be a nice idea..

The whole point of defining such a model method helps me returning "item_guid" in feed syndication. something like this:

def item_guid(self, item):
      return item.permalink()


Would it be a nice idea to define such a model method? 

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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate