def shorten_link(request): submit_link = request.GET['link'] #Need to replace the following with regexpression filteration if 'http://' not in submit_link: submit_link = 'http://'+submit_link link = Link.objects.get_or_create(link=submit_link,created_by=request.META.get("REMOTE_ADDR","")) #need to save the link obj first before we hash it because we are basing the hash on the unique ID if not link[0].link_short: #Get OR CREATE returns a tuple of the object and a boolean value - highlighting the object here [0] link[0].link_short = BASE_URL+baseconvert(link[0].pk,BASE10,BASE62) link[0].save() return render(request,'index.html',{'short_url':link[0].link_short},content_type="text/html") #BASE_URL from settings file
def firstsave(self): # Create hash self.hash = baseconvert(str(self.id),BASE10,BASE62) # Load url self.fetch_load_url() # Last datime self.last_usercall = datetime.datetime.now() self.save()