More Django Plugin Stuff
So I’ve been working more on the support for django within monodevelop. Heres some screenshots of it.


So I’ve been working more on the support for django within monodevelop. Heres some screenshots of it.


So I started to implement support for django with MonoDevelop. It currently has pretty good support for Python via PyBinding addon. At the moment I have only managed to add the ability to create a new django project, which acts in the same way as running
django-admin.py startproject projectname
But I aim to provide support to add new django apps to the project, once I get familiar with the MonoDevelop code base.
I have been playing about with django a fair bit over the last week. After written a small app with django I wanted to import some data from an existing MSSQL database. To get the data into the django model I created a seperate python script to perform the import. Below is a script to import data from a table compaines in a mssql data to a django model called Company. To connect to the mssql server I used the pymssql library.
#!/usr/bin/env python
import sys,os
os.environ['DJANGO_SETTINGS_MODULE'] ='settings'
# import the modules needed to start the import
import pymssql
from datetime import *
import unicodedata
from django.core.management import setup_environ
import settings
setup_environ(settings)
#import the django models
from apps.clients.models import *
def importCompanies(conn):
cur = conn.cursor()
cur.execute("""SELECT
liCompanyPk,
szCompanyName
FROM companies""")
row = cur.fetchone()
while row:
company = Company()
company.pk = row[0]
company.Name = row[1]
company.save()
row = cur.fetchone()
if len(sys.argv) != 5:
print 'data_import.py [server] [username] [password] [database]'
else:
print 'host=%s, user=%s, password=%s, database=%s' % (sys.argv[1],sys.argv[2],sys.argv[3],sys.argv[4])
conn = pymssql.connect(host=sys.argv[1], user=sys.argv[2], password=sys.argv[3], database=sys.argv[4])
importCompanies(conn)
conn.close()
After this I started to play around with pymssql I wanted a quick way to execute simple sql queries, not knowing of an linux alternative to the mysql console client I write another simple script to provide this basic functionality.
#!/usr/bin/env python import sys,os import _mssql if len(sys.argv) != 5: print 'data_import.py [server] [username] [password] [database]' else: print 'host=%s, user=%s, password=%s, database=%s' % (sys.argv[1],sys.argv[2],sys.argv[3],sys.argv[4]) conn = _mssql.connect(server=sys.argv[1], user=sys.argv[2], password=sys.argv[3], database=sys.argv[4]) print '>', cmd = raw_input() while cmd != 'exit': if cmd != '': print cmd try: conn.execute_query(cmd) for row in conn: for i in range(0,( len(row) / 2 )): print row[i],'|', print '' except _mssql.MssqlDatabaseException,e: print e print '>', cmd = raw_input(); conn.close()
You can download mssql_client.py here
So after only using for python for a couple of weeks It’s definitely powerful and fun to code with. Now to try out for all of the libraries that provide bindings such as pysvn or pyldap.
I have recently started having a play about with django. After reading loads of about it and have a little play about with snowy (a django based note sync for tomboy). After getting used to coding in python I found django really quick to develop in. But the documentation is by far the best thing about the project. There’s loads of the stuff, and its brilliant. Its readable. Its completely unlike reading other tech documents. If this isn’t a good selling point for checking it out then I don’t know what is because RTFMing has never been so easy.
Powered by Web Design Company Plugins
Aledr 8:47 pm on December 16, 2009 Permalink |
I’ve just installed MonoDevelop 2.2 and started a new Django project but is no option to create a new App there. Is your code already integrated?
Thanks.
John 11:11 am on December 17, 2009 Permalink |
I never got round to getting the code into a stable state, and submittting a patch. However I have a couple of weeks of work so I’ll see if have anytime to look at it again.