Wednesday, September 16, 2009 |
37 Comments | Auto Scaffold Django Admin Registration
Since the admin structure in Django changed (1.0?) I've found myself constantly feeling cheated that i have to actually create classes to get my admin system working - granted you usually want to create custom admin features for a model, but when you're just starting out with a project, the last thing you want to be doing is building generic admin classes and registering them with the admin app.
So, to combat this annoyance, i wrote a simple python script that i keep on my path on my mac, it just generates a scaffold of the admin classes i need for a project. Pretty simple.
#!/usr/bin/python
import sys
import re
if len(sys.argv) != 2:
print "Usage: adminscaffold <input-file>"
sys.exit()
arg = sys.argv[1]
inf = "%s/models.py" % arg
f = open(inf)
classes = []
registers = []
for line in f.readlines():
if re.match('class .*?\(models.Model\):',line):
(c,j) = line.split('(',2)
(j,cname) = c.split(' ',2)
classes.append("""
class %sAdmin(admin.ModelAdmin):
pass
""" % (cname))
registers.append("""admin.site.register(%s, %sAdmin)
""" % (cname,cname))
print """from django.contrib import admin
from %s.models import *
""" % (arg)
print "".join(classes)
print "".join(registers)
It's ugly and hacky, but it does do the job. Try it out.. basic usage is just:
$ django-admin-scaffold.py <app-name>
You run this in the same directory as your manage.py script.. and just provide the name of the app. It spits the code out on STDOUT, so you'll need to pipe it into a file to use it.




Reader Comments (37)
this is cool script thats for sharing .
i hope it so...thanks
This information is very nice and pleasant. Thank you for sharing
gadget and tech
Yes, It's pretty simple guys but look powerful. Thanks for sharing.
Thanks for sharing such great information. This site is very informative. I'm definitely going to keep this web data for future reference. thanks
Thank you for sharing useful information.I has visited your web site, a lot of information I can from your blog, thanks for the information.
Tks for this informations...
...This information is very nice and pleasant.i like it Thank you for sharing...
before I could thank allowed coment on your blog, I get lots of information from you, I wish I could be even more information from you
Awesome post!
Your blog is really nice!
I've found lots of helpful info!
Thanks.
Sajid says Thanks for the script/
I try to understand these script but I want to know how append function works?
Could you please clarify it?
Regards
satellite tv on internet
Hi, thanks for sharing.
Why don't you convert this script in a small app that add a standard django command? It would be nice and clean to use it with manage.py scaffold (or something like that).
<p>We are a professional supplier of wholesale designer handbags ,wholesale gucci,please feel free to
contact us if you need fashion handbags.
Find all the latest fashion, brown handbag, celebrity gossip and leather handbags!
Different Colors And Sizes Available. </p>
We take pleasure to introduce ourselves as manufacturers and exporters of all kinds of ladies high heel shoes.We are manufacturers and exporters of all kinds of high shoes. We specialize in wedding shoes fitted with Swarovski and imitation diamond
I really like your website http://soyrex.com , our website as well。coach outletis the market popular longest and most successful leather brand. Especially the coach handbagsand coach bags have a good reputation for quality and exquisite craft in female consumers.
MBT shoes
reebok easy tone
shape ups shoes
P90X
P90X Workout
P90X DVD-Fitness
birkenstock sandals
birkenstock gizeh
birkenstock Madrid
Breitling Watches are able-bodied accepted affluence cheap Breitling Aeromarine brands that accept been about for over 100 years. Accepted abnormally for bearing top attention sports Breitling Windrider and chronographs, these brands are consistently inventing and absolution new mechanisms and models that abide to amuse Bentley 6.75 admirers and accession the bar of watch making.
Christian Louboutin is a brand, which is feted for its great bag models. The bag models from Christian Louboutin Pumps are sometimes called status symbols, Christian Louboutin Boots make these bag models highly desirable for the purchaser who love luxury products. The brand has a great commercial worth as a keenly highly regarded brand. The Christian Louboutin Sandals has been in the luxurious products market for long period and is intensely trendy and elegant.
It is indeed a hard job for an average woman to find a Coach handbags that meets their style and organizational demands, as well as fits into their budget at the same time. You really need to set your priorities straight and strike a perfect balance between the aspects. With Coach Bonnie at least, it is perhaps best to prioritize style before organization as Coach Wristlet are primarily coveted because of Coach Ergo looks and not utility.
At the first look, these might look like the Air Jordan 7 jumpman shoes that released back in 2006. But, the colorway is entirely different from the pacific’s. These 7s sports a nice and clean white leather upper. Orion blue and michael jordans shoes are evenly split onto the sole, tongue, and heel. What do you think of this latest Air Jordan VII Retro?which just so happens to be a Thursday. Thursday is an unusual day for an Air Jordan release considering that most Jordan’s are released discount jordan shoes. For now, this release date change only applies to Foot Locker, but if any other retailers follow, we will let you know. This is great news for most people, but it could be bad news for some trying to save up with two less days. Look for these July 1st at Foot Locker locations and Footlocker.com
No sport event could have been air force ones shoes than the recent 2010 World Cup. And a lot of sneaker manufacturers who put some of their designs to be in line with the event will continue to delight air jordans shoe of sneaker fanatics. To further expand on encouraging team spirit, Puma came up with the Tekkies World Cup which is available at Puma City in New York.The Air jordan sneakers shoes Infrared Pack will go done as one of the best Jordan packages when Jordan Brand is all set and done. The pack caused major mayhem on the release date as limited numbers caused people to put blood and tears into their package.
<p>Eventually women began sporting these thick framed glasses too. This was also the sunglass shop the cat glasses for women first became popular. Many people are fond of wearing these 50’s inspired sunglasses up to now, including celebrities and fashion elites.Most people are fond of sunglasses shops eyeglasses from the golden age of fashion in order to make a fashion statement while others use these styles from celebrity sunglass to compliment their current styles further.</p>
<p>Aside from colored lenses, vintage designer shades also gave way to the mirrored type of sunglasses, which were very common in the 80s. These mirrored designer sungalsses are back in style again and even made more popular than ever thanks to the celebrities who flaunt them. Dark ray ban polarized sunglasses could be used for these mirrored sunglasses as well.
</p>
wholesale world cup soccer jerseys
2010 football t-shirts store
Brazil Team World Cup Soccer Jersey
2010 Argentina Team World Cup Soccer Jersey
NBA basketball jerseys
men basketball jerseys
Discount Louis louis vuitton handbags Vuitton Handbags,Wallets & Purse louis vuitton Online Store. In
louis vuitton replica handbags the my lv replica handbags store buy designer handbags cheap Louis louis vuitton handbags Vuitton Handbags, You replica handbags best choice.louis vuitton,louis vuitton handbags,louis vuitton handbag,louis louis
vuitton handbags vuitton bags,louis vuitton bag,louis vuitton wallets,louis vuitton wallet,gucci,gucci wholesale louis vuitton
handbags handbags,gucci handbag,gucci bags,gucci bag,gucci wallets,gucci wallet,prada,prada handbags,prada handbag,prada bags,prada wholesale replica handbags bag,prada wallets,prada wallet,buy prada handbag.
815GSW0715
louis vuitton
louis vuitton handbags
louis vuitton
replica louis vuitton shoes
lv handbags
chanel bags
louis vuitton hanbags
cheap louis vuitton
replica louis vuitton bag
louis vuitton shoes
balenciaga bags
replica christian louboutin shoes
prada shoes
replica louis vuitton
Latest insanity workout dvd
insaity workoutLet you have vigor
cheap insaity workoutLet you be stronger
px90-insanitymake you healthier
Px90
px90 exercise program
Mbt shoesspecial style
Mbt safiridifferent designs
MBT ChapaPersonality
welcome to buy!thank you!
Latest insanity workout dvd
insaity workoutLet you have vigor
cheap insaity workoutLet you be stronger
px90-insanitymake you healthier
Px90
px90 exercise program
Mbt shoesspecial style
Mbt safiridifferent designs
MBT ChapaPersonality
welcome to buy!thank you!
coach outlet
coach outlet
coach handbags
coach factory outlet
coach factory outlet store
coach outlet
Thanks for your sharing! great helpful!!!I am pleased to share my joy with you? 2010-07-22
Coach outlet Coach outlet
Gucci outlet Gucci outlet
Coach outlet store Coach outlet store
Gucci outlet online Gucci outlet online
Coach factory outlet Coach factory outlet
Gucci handbags Gucci handbags
coach outlet online Coach outlet online
This article is written by zocy003 on 2010-7-23 http://www.coachoutletmalls.com