I am going to outline my workflow and I would like some suggestions on how to improve the efficiency of this. It seems right now a bit cumbersome and repetitive (something I hate), so I am looking for some improvements. Keep in mind I'm still new to django and how it works but I'm a pretty fluent coder (IMHO). So here goes...
TextMate Project http://img.skitch.com/20090821-g48cpt38pyfwk4u95mf4gk1m7d.jpg
In the first tab of the terminal start the server
python ./manage.py runserver
In the second tab of the terminal window start the shell
python ./manage.py shell
This spawns up iPython and let's me start the development workflow
Create and build a basic Model called models.py
Build a basic Model
class P4Change(models.Model):
"""This simply expands out 'p4 describe' """
change = models.IntegerField(primary_key=True)
client = models.ForeignKey(P4Client)
user = models.ForeignKey(P4User)
files = models.ManyToManyField(P4Document)
desc = models.TextField()
status = models.CharField(max_length=128)
time = models.DateField(auto_now_add=True)
def __unicode__(self):
return str(self.change)
admin.site.register(P4Change)
> python ./manage.py syncdb
Creating table perforce_p4change
Installing index for perforce.P4Change model
> python ./manage.py shell
Python 2.6.2 (r262:71600, Apr 23 2009, 14:22:01)
Type "copyright", "credits" or "license" for more information.
IPython 0.10 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.
In [1]: from perforce.models import *
In [2]: c = P4Client.objects.get_or_create("nellie")
The point of this is for all of you geniuses out there to show me the light on a more productive way to work. I am completely open to reasonable suggestions. I'm not inclined to shift tools but I am open to criticisms.
First of all, no need to do a ./manage.py runserver
until your models are in place.
Second, clear the database/rebuild the database should be done after fixing the code, and can be done in one fell swoop with ./manage.py reset perforce
Third, the things that you are typing out in the shell each time (import models, try creating an object) should be written in a test suite instead. Then you can do ./manage.py test perforce
instead of firing up the shell and typing it again. Actually, if you're using the test suite, you won't need to, because it will create a clean dummy db each time, and break it down for you when it's done.
Fourth, Instead of "PRAY...", try "Watch tests pass."
I find it smoother to write unit tests more often and only use the shell when something is failing and it's not obvious why and you want to poke around to figure it out. It is a little more inefficient at the very beginning, but quickly becomes a wonderful way to work.
I also tend to concentrate on getting the model more or less stable and complete (at least as far as what will affect table structure) before I work on the views and need to run the server. That tends to front-load as many resets as possible so you're doing them when it's cheap.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With