Last active
April 6, 2018 06:23
-
-
Save lmchawla/7dc1a6c59e620823cc27cff2e1d22341 to your computer and use it in GitHub Desktop.
Parse forms into django
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a=$('input'); | |
var output=''; | |
for(var i=0;i<a.length;i++){ | |
if($(a[i]).attr("type")=="text"){var prev=$(a[i]).closest('td').prev('td'); | |
if(prev.text().trim()==':') | |
{prev=prev.closest('td').prev('td');} | |
txt=prev.text().trim(); | |
req=false; | |
if(txt.substring(txt.length-1, txt.length)=="*"){ | |
req=true; | |
txt=txt.substring(0, txt.length-1) | |
} | |
txt=txt.trim(); | |
var name=txt.toLowerCase().split(".").join("").split("/").join("").split('-').join('_'); | |
name = name.replace(/\s\s+/g, " "); | |
name=name.split(" ").join("_"); | |
output=output+(name+'=models.CharField(max_length=255,verbose_name="'+txt+'")')+'\n'; | |
} | |
console.log(output); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment