I have a Django model that looks something like this:
class Person(models.Model):
name = models.CharField(max_length=32)
place = models.ForeignKey(Place, related_name='people')
approved = models.BooleanField()
objects = PersonManager()
@models.permalink
def get_absolute_url(self):
return('deal_details', (), {
'person_slug': slugify(self.name),
})
As you could see, I already have an absolute URL for the object. However, I want to create a difficult-to-guess URL to keep track of the approval process of the object. Anyone done something similar and/or have any suggestions on how I should proceed?
My first thought was creating a model field like obfuscated_key that is generated randomly via the save function of the model. Then the URL would look something like /people/status/<id>/<obfuscated_key>/. But perhaps there’s a better way to go about this?
A good way to do this would be to hash the object’s ID with the installation’s secret key (from settings.py). This is what the password reset email form does – there’s some useful code in
django.contrib.auth.tokens– and, in the very latest SVN versions,django.contrib.auth.crypto.