Elisp func to create a dummy admin.py

While writing a django app, I faced the tedious task of updating the corresponding admin.py file for the models I was writing. Because I didn’t want to customize any of the admin options just yet all I had to do is insert new register entries on the file (one for model). I grew tired of this pretty soon so I wrote this elisp function to update an admin.py file easily. Hope this helps somebody

(defun rl/django-admin-all-models()
(interactive)
(let ((content " "))
  (with-temp-buffer
    (insert "from models import *\n")
    (insert "from django.contrib import admin\n\n")
    (let ((text-start (point)))
  (insert-file-contents "models.py")
  (keep-lines "^class.*$" text-start (point-max))
  (while (re-search-forward "^class \\(\\w+\\).*" nil t)
    (replace-match "admin.site.register(\\1)"))
  (write-file "admin.py" nil)))))

A word of warning: this will override your current admin.py

TwitterGoogle+FacebookRedditEmail