Skip to content

Instantly share code, notes, and snippets.

@lmchawla
Last active April 6, 2018 06:23
Show Gist options
  • Save lmchawla/7dc1a6c59e620823cc27cff2e1d22341 to your computer and use it in GitHub Desktop.
Save lmchawla/7dc1a6c59e620823cc27cff2e1d22341 to your computer and use it in GitHub Desktop.
Parse forms into django
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