Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 336671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:15:52+00:00 2026-05-12T10:15:52+00:00

I am going to outline my workflow and I would like some suggestions on

  • 0

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…

Tools (I use these everyday so I’m not inclined to shift):

  • Mac OSX Leopard
  • TextMate
  • Terminal w/tabs
  • Perforce

Assumptions

  • Django Basics (Did the tutorials/bought the books)
  • Python Fluent (running 2.6 with IDLE Support)
  • Starting my first Application working on models.py

Starting out

  • Create a TextMate Project with the entire django Tree inside of it.

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

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)
  • In the first terminal (Running server) stop it ^C and syncdb start server

>  python ./manage.py syncdb
Creating table perforce_p4change
Installing index for perforce.P4Change model
  • In the shell terminal window load it..

> 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")
  • Did it break yes/no if it did not work then do this:
    • Stop the shell
    • Clear the database
    • Rebuild the database
    • Fix the code
    • Reload the shell
    • Reload the modules
    • PRAY…

Issues / Comments / Thoughts

  • Is it me or does this seem terribly inefficient?
  • It seems like I should be able to do a reload(module) but I can’t figure out how to do this.. Anyone?
  • It would seem as though I should be able to test this from within TextMate?? Anyone??
  • Even to just get out of the shell I have to verify I want to leave..

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T10:15:52+00:00Added an answer on May 12, 2026 at 10:15 am

    Thanks to everyone who read this and is looking for a better way. I think unit tests are definately the simpler approach.

    So according to the docs you simply need to create a file tests.py parallel to models.py and put tests in there.

    from django.test import TestCase
    from perforce.models import P4User, P4Client
    
    class ModelTests(TestCase):
      def setUp(self):
        self.p4 = P4.P4()
        self.p4.connect()
    
      def test_BasicP4(self):
        """
        Make sure we are running 2009.1 == 65
        """
        self.failUnlessEqual(self.p4.api_level, 65)
    
      def test_P4User_get_or_retrieve(self):
        """
        This will simply verify we can get a user and push it into the model
        """
        user = self.p4.run(("users"))[0]
        dbuser = P4User.objects.get_or_retrieve(user.get('User'))
    
        # Did it get loaded into the db?
        self.assertEqual(dbuser[1], True)
    
        # Do it again but hey it already exists..
        dbuser = P4User.objects.get_or_retrieve(user.get('User'))
        # Did it get loaded into the db?
        self.assertEqual(dbuser[1], False)
    
        # Verify one field of the data matches
        dbuser = dbuser[0]
        self.assertEqual(dbuser.email, user.get("Email"))
    

    Now you can simply fire up the terminal and do python manage.py test and that will run the tests but again that’s a pretty limited view and still requires you to swap in/out of programs.. So here is how you do this directly from Textmate using ⌘R.

    Add an import line at the top and a few line at the bottom.

    from django.test.simple import run_tests
    #
    # Unit tests from above
    #
    if __name__ == '__main__':
      run_tests(None, verbosity=1, interactive=False)
    

    And now ⌘R will work directly from TextMate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is going to smell like a duplicate but it isn't. I've tried this:
Going through some of my older Delphi projects and upgrading them to D2009, as
Going mad now. I have a MVC solution that i've upgraded from MVC 1
Going through some documentation on modifying CGImageRef data, I came across a strange example
I'm going to outline my problem in detail to explain what I'm trying to
For a certain style I'm going for, I want to outline a group of
There doesn't seem to be much info on this topic so I'm going to
I have a collection that is potentially going to be very large. Now I
I use this reset. * { font-family: Arial, Helvetica, sans-serif; outline: 0; padding: 0;
I have bug checked this code considerably now and made sure I am outputting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.