Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
jarito
Aug 26, 2003

Biscuit Hider
I've decided to take a look into Django and I had some quick questions. From Java / ASP development, I've gotten spoiled in having really good IDE's. Is there a good ide for Python? By good I mean at least has syntax highlighting, intellisense and debugger integration. Project management would be a bonus but I guess it is not required.

Adbot
ADBOT LOVES YOU

jarito
Aug 26, 2003

Biscuit Hider
I generally develop on Windows these days due to a lot of ASP.NET projects, but I still run Linux so either of those would be fine. So the only options are Vim / Emacs (TextMate is OSX only, yes?). That's disappointing. There aren't any plugins for Eclipse or something of that nature that do intellisense? I've never been that fond of vim / emacs, but I guess I can use them if I really have too.

I disagree about the debugger comment, but that's a whole different conversation. :)

jarito
Aug 26, 2003

Biscuit Hider
I have a quick question about master templates and such. I have one master template that works fine, but I was curious how to handle dynamic data in the different blocks. Let's say I have something like this for the master template (lots of the basic code omitted).

code:
<!-- Header -->
<div id="header">
    {% block login %}{% endblock %}    
</div>        
	       
<!-- Main Content -->  
<div id="container">
    <div id="center" class="column">	 
        {% block center %}{% endblock %}        
    </div>
</div>
I want the login block to show the user's name and a logout button if the user is logged in or a username / password block if they are not. The trick is, I want that to show on all the pages. How to I set it up to run multiple view functions for one request? Each page is filling in the 'center' block with the page content...

jarito
Aug 26, 2003

Biscuit Hider
Thanks for all the help guys, I will give that a shot.

jarito
Aug 26, 2003

Biscuit Hider
Okay, another newbie question :). I'm used to be easily able to do multiple operations on one page (from ASP.NET) so I might be off, but here's what I want to do. I would normally do this all one one page (AJAX will come later).

1. Have the user enter a piece of data.
2. Perform a web service request and display options.
3. User selects an option.
4. Store data from the selected option in the DB.

I have the web request working, but I don't really seem to be able to get the control flow to work. I have a view named 'add'. Here is the urls.py

code:
urlpatterns = patterns('',  
  (r'^$', 'django.views.generic.list_detail.object_list', info_dict, 'book_list'),
  (r'^(?P<object_id>\d+)/$', 'django.views.generic.list_detail.object_detail', info_dict),
  (r'^add/$', 'books.views.add'),
)
This forwards request for 'books/add' to the correct view function which is here:

code:
def add(request):
  if request.POST.__contains__('books_isbn'):
    return render_to_response('books/books_add.html')
  else:
    return render_to_response('books/books_add.html', {
            'book': lookup_book(request.POST['book_isbn']),})
So it checks to see if 'books_isbn' in the POST and if so, returns the same view (books/add) with the results of the lookup. If 'books_isbn' is not there, then it should just render the page (since it should be the first request.)

The problem is that the 'request.POST.__contains__('books_isbn'):' always seems to return true since the error I get is:

code:
MultiValueDictKeyError at /books/add/
"Key 'book_isbn' not found in <QueryDict: {}>"
I also tried 'request.POST.has_key('books_isbn') with the same results. Am I going about this the wrong way? Is there a more accepted way to do what I am trying to do?

Also as a side note, what is the standard tab=space settings for python code?

jarito
Aug 26, 2003

Biscuit Hider
Is there anyway to have syncdb just drop all the tables and reinsert them? At least for one application? I am porting an existing app and when I mod a table to add fk relationships, etc. it is really annoying to have to delete the tables by hand and then let django re-add them.

Perfect would be leaving the django stuff alone (admin, auth, etc) but dropping all tables related to a specific app and re-adding them.

jarito
Aug 26, 2003

Biscuit Hider
Sounds great. That should tide me over until the schema gets a little more definite. Got another stupid admin question. I have this in my models.py:

code:
class Contact(models.Model):
    title = models.CharField(max_length=8, blank=True)
    first_name = models.CharField(max_length=50)
    middle_name = models.CharField(max_length=50, blank=True)
    last_name = models.CharField(max_length=50)
    suffix = models.CharField(max_length=10, blank=True)
    other_languages = models.CharField(max_length=255, blank=True)
    
    class Admin:
        pass
  
    def __unicode__(self):
        return '%(last)s, %(first)s' % { 'last': self.last_name, 'first': self.first_name }

class Patient(models.Model):
    birthdate = models.DateField()
    contact = models.ForeignKey(Contact)
    emergency_contact = models.ForeignKey(Contact, related_name='emergency_contact', null=True)
    
    class Admin:
        pass
  
    def __unicode__(self):
        return contact
But for some reason, the Admin interface still requires that I select an emergency_contact, even though it is marked as nullable (both in the models.py and the database). I was using this example which has this code:

code:
class Reporter(models.Model):
    name = models.CharField(max_length=30)

    def __unicode__(self):
        return self.name

class Article(models.Model):
    headline = models.CharField(max_length=100)
    reporter = models.ForeignKey(Reporter, null=True)

    class Meta:
        ordering = ('headline',)

    def __unicode__(self):
        return self.headline
Am I going about this the wrong way?

jarito
Aug 26, 2003

Biscuit Hider
I got a interesting one for you all. We have been tasked with creating a new site that has some interesting properties. I could use some help since I'm still starting with Django.

The idea is to create a 'reference' site that implements all the features we need. This part I can do. I create a project with an application called super. This all works fine.

Here's the interesting part. I need to create an unlimited number of subsites. The subsites use the same models / db. The subsites will differ mostly in images and css, but sometimes they will need to modify the templates as well.

So the idea is that the subsites will use the super site's implementation, templates and views UNLESS the subsite defines it's own, then those should be used. I'd like to do this without copying anything over and over again so if changes need to be made, they only need to be made in one place.

My idea was to have the views in the reference site load templates based on a setting. The subsites would override this setting to their individual template dirs, but would check for the existence of a template and if one isn't found, use the reference template.

Am I right that I can have the subsites inherit the views from the supersite and then just override any methods that it wants to implement?

How would I do this for the site_media stuff? Images / css should be loaded from the subsite specific folders unless they don't exist, then they should load from the supersite...is that possible?

jarito
Aug 26, 2003

Biscuit Hider
Quick question. I was reading up on the Sites framework and I had a quick question. I have a set of sites that I want to run on the same DB and share the same Models, how would I go about setting that up?

When I do startproject I get the settings, manage and urls files. Then under that I create an app that has views / models. To share the models, do I create my sites as sub-projects of the project or do I create multiple projects and somehow include the models file?

So, this:
code:
/myapp
   - settings.py
   - manage.py
   - urls.py

   /myproject-1
      - models.py
      - views.py
   /myproject-2
      - models.py (uses the models from myproject-1)
      - views.py
   /myproject-3
      - models.py (uses the models from myproject-1)
      - views.py
or this:

code:
/myapp
   - settings.py
   - manage.py
   - urls.py

   /myproject
      - models.py
      - views.py
      /sub-project-1
         - views.py
      /sub-project-2
         - views.py

jarito
Aug 26, 2003

Biscuit Hider
Saw this on reddit:

http://groups.google.com/group/django-developers/browse_thread/thread/815f76ad7e823cbf?hl=en

Benchmark Performance:

quote:

Summary results:
Signal sends with no listeners in process: 67% faster
Signal sends with no listeners, but 10 other listeners on different signals: 91% faster
Signal sends with 30 weakref receivers: 60% faster
Signal sends with 30 strongref receivers: 67% faster

Semi-Real World (Test Suite):

quote:

I'm seeing about a 40% improvement in
the running of the test suite (from 500s down to 300s). That's just
loving awesome. On top of that the net -500 LOC is very, very nice :)

Seems like 1.0 is going to be quite a bit faster.

Adbot
ADBOT LOVES YOU

jarito
Aug 26, 2003

Biscuit Hider
Just getting started with a project at work in Django. The app is a pure ReST interface (no web front end). I've noticed there are some plugins for making ReSTful Django interfaces, but the basic Django handlers and stuff seem like they would work fine.

For a pure ReST interface app, should I use a library / plugin? Or just use the basic handlers from Django?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply