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
StabbinHobo
Oct 18, 2002

by Jeffrey of YOSPOS

bitprophet posted:

StabbinHobo, you don't work in the journalism field, do you? Not at a paper in JC perhaps?
indeed. you interview?

Adbot
ADBOT LOVES YOU

Tap
Apr 12, 2003

Note to self: Do not shove foreign objects in mouth.
Well after some careful deliberation, I picked up my first two Python books. Learning Python and Programming Python (both O'Reilly). I'm currently learning PHP, because I desire to get a job in web development (and I feel that, with a nice PHP background that my job choices will be broader). But I plan on picking up the Python books soon and taking a stab at it.

Here's to a long future with Python!

bitprophet
Jul 22, 2004
Taco Defender

StabbinHobo posted:

indeed. you interview?

I did, last summer actually, but ended up going with the place I'm at now (sorry!). Good luck with the hiring, if I run into anyone looking for Django work I'll send them your way :)


Tap posted:

Here's to a long future with Python!

:neckbeard:

ATLbeer
Sep 26, 2004
Über nerd
http://code.google.com/appengine/

Django support out of the box :hawaaaafap:

It's the only framework supported :holy:
http://code.google.com/appengine/articles/django.html

Grr... Looks like the parts that are supported are only the request handling, and template engine side. No support for the Django ORM. Looks like there's already a problem on the Dev side about BigTable and the Django ORM mixing since BigTable has built in support for joining.

ATLbeer fucked around with this message at 15:50 on Apr 8, 2008

Senso
Nov 4, 2005

Always working
I've installed everything on Windows as I'll be testing it on XP before moving to a Linux server.

I've installed Apache2, Postgresql 8.3.1, etc. Then I got this error:

code:
C:\django\blog>python manage.py syncdb
Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    execute_manager(settings)
  File "C:\Python25\Lib\site-packages\django\core\management.py", line 1672, in execute_manager
    execute_from_command_line(action_mapping, argv)
  File "C:\Python25\Lib\site-packages\django\core\management.py", line 1571, in execute_from_command_line
    action_mapping[action](int(options.verbosity), options.interactive)
  File "C:\Python25\Lib\site-packages\django\core\management.py", line 504, in syncdb
    cursor = connection.cursor()
  File "C:\Python25\Lib\site-packages\django\db\backends\postgresql_psycopg2\base.py", line 57, in cursor
    postgres_version = [int(val) for val in cursor.fetchone()[0].split()[1].split('.')]
ValueError: invalid literal for int() with base 10: '1,'
So I went in \Lib\site-packages\django\db\backends\postgresql_psycopg2\base.py and printed the value that caused the error to see what was the problem. It turns out that doing
code:
SELECT version()
('PostgreSQL 8.3.1, compiled by Visual C++ build 1400',)
There is a comma after the version number. So I made a simple change to postgresql_psycopg2\base.py:

code:
postgres_version = [int(val) for val in cursor.fetchone()[0].split()[1].split('.')]
TO
postgres_version = [int(val[b].strip(',')[/b]) for val in cursor.fetchone()[0].split()[1].split('.')]
And I was able to run syncdb without problem. I got that problem after following the Windows setup tutorial in the OP so just in case someone else gets the same issue...

bitprophet
Jul 22, 2004
Taco Defender
Senso, if you have a minute, you should definitely do a quick search on the Django bug tracker to see if there's a ticket for this already, and if not, make a quick one with the info you just posted - it sounds like this might be a genuine minor bug in the Postgres support, and if so, it'd be great to have it officially reported so it can be fixed in trunk :)

vvv Thanks!

bitprophet fucked around with this message at 22:06 on Apr 8, 2008

Senso
Nov 4, 2005

Always working

bitprophet posted:

Senso, if you have a minute, you should definitely do a quick search on the Django bug tracker to see if there's a ticket for this already, and if not, make a quick one with the info you just posted - it sounds like this might be a genuine minor bug in the Postgres support, and if so, it'd be great to have it officially reported so it can be fixed in trunk :)

Good idea. I assumed it was already fixed but I did a search and found a similar problem with MySQL but not with PostgreSQL.
So I've opened Ticket #6987.

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.

bitprophet
Jul 22, 2004
Taco Defender

jarito posted:

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.

Gotta specify your platform...:)

Any programmer's editor will do syntax highlighting for Python, and most of the extensible ones (Vim, Emacs, TextMate, etc) will probably have third party Django template language bundles available. Debugger integration varies; debuggers aren't typically (in my experience) terrifically useful/applicable to Web development, but for stuff that can be tested outside of the Web context, there are Python debuggers such as pdb, and again many editors have hooks for them.

From what I've seen, though, most Django devs don't find themselves needing the big beefy IDE setup that Java, etc practically require. Autocomplete, syntax highlighting and a terminal = good to go.

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. :)

bitprophet
Jul 22, 2004
Taco Defender

jarito posted:

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. :)

Oh, no, I wasn't giving an exhaustive list. Pretty sure the default Python distribution comes with something called IDLE, that might be Windows only, not sure. No idea how good it is - I use TextMate which is OS X only.

Eclipse should definitely have Python support, not sure if it has Django specific support. Google around for "(python OR django) IDE" and I'm sure you'll find blog posts / discussions.

vvv I actually use vim more than TM nowadays since I spend a lot of time remotely editing...it is pretty awesome :)

bitprophet fucked around with this message at 02:58 on Apr 9, 2008

No Safe Word
Feb 26, 2005

bitprophet posted:

Eclipse should definitely have Python support, not sure if it has Django specific support. Google around for "(python OR django) IDE" and I'm sure you'll find blog posts / discussions.


Eclipse has PyDev for Python support, nothing specific to Django that I've found. I actually prefer vim anyway though ;) (on Windows and Linux)

Senso
Nov 4, 2005

Always working
I've tried so many editors but, on Windows, Notepad++ is the one I prefer. It's quick, has dozens of specific plugins, good syntax highlighting and code folding, tabs and more.

WickedMetalHead
Mar 9, 2007
/dev/null
I normally use Wing IDE Personal. There's supposed to be a way to integrate Django with it for Debugging and what not but i havn't really messed with it all since its easier to just debug with the dev server normally.

No Safe Word
Feb 26, 2005

http://djangopluggables.com/

Nice repository full of django apps you can plug into your site.

tehk
Mar 10, 2006

[-4] Flaw: Heart Broken - Tehk is extremely lonely. The Gay Empire's ultimate weapon finds it hard to have time for love.
ATLbeer, thanks for the awesome first Django/Web experience. I haven't done much web development and basically spent most of my time working on imaging libraries and various python projects. So this is a refreshing experience and exciting since I am getting right into the action rather then learning php or brushing up my ruby skills. So thanks!

Also, I am using Eclipse and PyDev(an eclipse extension for python development) and it works wonderfully with Django after you add the django site-package path. For anyone who is looking for an editor check it out pydev/eclipse is fairly advanced. I also tried dong some django work in wingIDE, but its pricey unless you go thru the free copy for open source developers process(the biggest hurdle is waiting for the snail mail).

The Real Ambassador
Apr 9, 2005

I'll explain and make it plain, I represent the human race.
I've just been getting into Django and I really really like it. Here's the long-winded rant/odyssey about how I finally found a way to develop web-apps that finally seems makes sense to me:

I've been using PHP for the past five years and have always hated it. As Larry Wall once said, PHP really does bring "worse is better" to new levels. Though I appreciate PHP's practicality for small scripts, it's universal support, and how it was responsible for making the development of dynamic websites accessible to mere mortals, it really is just a horrible awful programming language.

For the past few years I've been trying to find a viable Perl alternative. I know Perl pretty darn well and it just seems every time every time I try to get something like Catalyst, Embperl, or Mason working, it just turns into a nightmare. The CPAN installs always fail, nothing can "just work" from the beginning, and I'm forced to try and figure out if I want Apache::Session, Embperl::Session, Apache::SessionX, and then it forces me to decide where to store the data for my sessions, and oh wait, CentOS 3 or 4? has mod_perl 1.99.FAIL which will make everything blow up no matter what you do, and they refuse to issue a working alternative RPM. Can't Perl just work??? It's a fun, expressive language, and I don't know if these problems arise from the "there is more than one way to do it" philosophy, or the fact that the "all-star" Perl developers are all focused on bulking up Perl 6's vaporware.

I also tried to just develop simple applications with mod_perl. Mod_perl is pretty clean and simple these days (since the 1.0 -> 2.0 insanity) and has really good support across distros and cpanel. I wrote some Apache handlers with mod_perl and I thought it was totally awesome how lightning fast they were, especially with database access. The only problem is that in order to write a web app on mod_perl alone, I'd really be on my own. I'd have to pick and choose my CPAN modules and hope that people are using them in the future, and "roll my own" of so many things, that it just didn't seem practical for rapid web application development.

So I ran back to PHP and cried a lot. About a month or so ago I decided to try Ruby out. I had seen their screencasts, and a post-grad friend of mine always raves about Ruby's OOP purity, so I figured I'd give Ruby and Rails a chance.

I learned a bit of Ruby, and it's definitely not as mature as Python and Perl in terms of having a large collection of libraries for doing various things. I downloaded the MySQL extension and started goofing around and had some fun. The language didn't feel as responsive on the command line like Python and Perl, but that's no problem.

Then I started trying to learn Rails. At this point the latest version is 2.x and I just couldn't seem to find ANY decent up-to-date learning material aside from the reference manual. The tutorials and screencasts I did find, left me with a simple webapp that worked, but without any understanding of how all the RoR's black magick involved in created that app (like scaffolding) works. One major tutorial (I think it was the official one) had blatently wrong errors that I had to work around. In the end I just felt like I spent two days watching a bunch of guys "show off". After doing a little more research on the poor status of rails documentation, the general consensus of the blogging community seems that the Rails people are more interested in getting you to buy the book.

I also didn't like that the current recommended strategy for production use of rails is to Proxy requests through Apache to a bunch of mongrel processes. In order to do this, you need a bleeding edge version of Apache which just isn't practical if you want to deploy on an existing server. I managed to setup a mongrel cluster on my home computer (4-core 2.6ghz core 2 CPU) and if I recall correctly I got about 1000 requests per second on a hello world app. This isn't terrible, about the same speed as a hello world PHP app, but I could get django to go much much faster.

I also didn't like Ruby so much as a language. I think it's amazing that it's essentially a pure OOP language like SmallTalk, only with modern syntax (even though its purity might make the language a little less practical in terms of speed) I was also happy to find built-in support for Perl's regular expressions; however, I feel Ruby took a bit too much of the ugliness of Perl with it. (Matz even admits this) Another really really big problem with Ruby is that it doesn't support [a=http://spec.ruby-doc.org/wiki/Ruby_Threading]"real" threads[/url]. This was a really bad design choice considering the way CPUs are being built these days, and that flaw alone, is reason enough to not take Ruby as a "serious" language for general purpose for business use. (Yes this will probably be fixed with other VMs or implementations in the future)

So after failing miserably in learning Ruby on Rails, I found out about Django. I went through the getting started tutorial, and as soon as I read that the preferred production setup was PostgreSQL with Apache/mod_python, I instantly knew these guys were serious about developing a practical, scalable framework. As I started learning how to do things, I was amazed that, it seemed like the first time ever, that things were actually making sense!. Probably what I love the most is that the Django people take an amazing approach to documentation: instead of showing off all these neat magical features, they start by showing you the "dumb" way to do something so you can understand what's happening from top to bottom, then they gradually show you all the shortcuts and design patterns Django offers to make life easier. And best of all, Django is FAST! On one of my xeon servers, I could get a hello world app in Django to perform pretty much on-par with a mod_perl apache module. Not only was the framework simple, it was lightweight.

So I'm very excited about Django, but I won't know for sure if it's the as good as I hope it will be until I actually write a full web application with it. So in closing, I'd just like to say that I sincerely thank those of you (especially ATLbeer) who are putting their time and effort into making Django better and more mainstream.

tehk
Mar 10, 2006

[-4] Flaw: Heart Broken - Tehk is extremely lonely. The Gay Empire's ultimate weapon finds it hard to have time for love.
I have a quick question regarding the subclassing of models. My code has a few models which share a decent amount of common attributes and I am wondering if making a superclass then subclassing it would work well. I heard some chatter last year about subclassing not working well with models is this still the case(maybe in 0.96)? Is inheritance broken for models?

Withnail
Feb 11, 2004
I don't want to make a new thread so I'll ask here. I'm looking at doing a new web project either in php or python. I've tentatively started with php using code igniter. It's been a few years since I used php heavily and have been working mostly on java/struts apps and a little asp.net.

I've been finding it a little difficult to work in java all day and then switch gears to php at night. Generally speaking, is python/django going to be an easier transition for web apps than php?

bitprophet
Jul 22, 2004
Taco Defender

tehk posted:

I have a quick question regarding the subclassing of models.

Model subclassing is still not officially in, but the queryset-refactor branch (which will hopefully hit trunk in the next, I dunno, month or two maybe?) has implemented it: http://code.djangoproject.com/changeset/7126#file8

So if you're willing to use an unstable branch, you could check out that version of Django and give it a whirl. I haven't used it at all.

Withnail posted:

I've been finding it a little difficult to work in java all day and then switch gears to php at night. Generally speaking, is python/django going to be an easier transition for web apps than php?

Depends partly on what you mean by "easier"; PHP's syntax is a little closer to Java than Python's is (what with the semicolons and curly braces and all). In terms of overall web development paradigms, I've never used Struts so I can't really say there.

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...

WickedMetalHead
Mar 9, 2007
/dev/null
jarito, you can use context to determine if the user is logged in or not, I can't think of the exact sytanx in my head right now, but the template code would be something like "If user.something (can't reacall the name, its in the docs though)" then {{ user.username }}, else, print your login block. You can either use a context processor to put a form object in the context of every page, a template tag, or manually code in a form.

king_kilr
May 25, 2007

jarito posted:

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).

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...

You can actually do this logic in the master template(assuming you want it in all child templates):

code:
{% if user.is_authenticated %}
    Hello {{ user.username }}
{% else %}
    {# Show the login form #}
{% endif %}
If you only want it in some templates I would make a template that extends the base one that overrights the login block and nothing else and have templates that need the login to extend that, and have other ones extend the main base.

You will need to have RequestContext for this to work(of course).

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?

The Real Ambassador
Apr 9, 2005

I'll explain and make it plain, I represent the human race.

jarito posted:

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?
Your if statement logic should be reversed. Change:
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']),})
to:
code:
def add(request):
    if 'books_isbn' not in request.POST:
        return render_to_response('books/books_add.html')
    else:
        return render_to_response('books/books_add.html', {
                  'book': lookup_book(request.POST['book_isbn']),})
The problem is when the code "request.POST['book_isbn']" gets called. If the value doesn't exist, an exception is raised.

May I also suggest you put the ISBN in the URL? ISBNs are only numbers and hyphens so it should look fine, and allow people to copy and paste the URL. Example: http://mysite.com/book/isbn/978-3-16-148410-0/

jarito posted:

Also as a side note, what is the standard tab=space settings for python code?
I believe the vast majority of people use 4-space tabs. I strongly recommend against using tabs with Python because each editor seems to do its own wacky thing when in "tabs mode" and your source can easily get unaligned, if not interpreted incorrectly by Python.

The Real Ambassador fucked around with this message at 07:13 on Apr 15, 2008

duck monster
Dec 15, 2004

bitprophet posted:

Model subclassing is still not officially in, but the queryset-refactor branch (which will hopefully hit trunk in the next, I dunno, month or two maybe?) has implemented it: http://code.djangoproject.com/changeset/7126#file8

So if you're willing to use an unstable branch, you could check out that version of Django and give it a whirl. I haven't used it at all.


Depends partly on what you mean by "easier"; PHP's syntax is a little closer to Java than Python's is (what with the semicolons and curly braces and all). In terms of overall web development paradigms, I've never used Struts so I can't really say there.

PHP's syntax is sort of like javas. But honetstly, PHP's actual language isn't in the ballpark. Python does real OO, and does it loving well (Granted php5 is starting to look a bit more like real oo) and for added fun, you can still hang out in java land using Jython (or c# land using ironpython) and it all works smooth as poo poo. Hell, Java's Groovy is a pretty much self confessed rip of python but java-ish.

In re to the glowing review a bunch of posts back. Python is awesome, but its threading won't get you multiple core utilisation without some deep thought. Incidently tell guido to make that global interpreter lock gtfo, since thats what holds the multicore stuff back.

The Real Ambassador
Apr 9, 2005

I'll explain and make it plain, I represent the human race.

duck monster posted:

PHP's syntax is sort of like javas. But honetstly, PHP's actual language isn't in the ballpark. Python does real OO, and does it loving well (Granted php5 is starting to look a bit more like real oo) and for added fun, you can still hang out in java land using Jython (or c# land using ironpython) and it all works smooth as poo poo. Hell, Java's Groovy is a pretty much self confessed rip of python but java-ish.
I agree, Python feels a lot like Java in many way. They both share a similar packaging system, strong OOP features, and the "There Is Only One Way To Do It" philosophy. What I like about Python is it "fits in" better with the *nix world, doesn't take 3 seconds to load the VM, is simpler, and in my opinion, more practical for general development.

It really irritates me when people think languages are similar because they both have curly brackets.

The Real Ambassador fucked around with this message at 09:04 on Apr 15, 2008

bitprophet
Jul 22, 2004
Taco Defender

The Real Ambassador posted:

It really irritates me when people think languages are similar because they both have curly brackets.

Heh, well I was only throwing that out because it's been years since I used Java heavily (university; been using Python exclusively since I graduated) and didn't feel qualified to speak on the more meaningful similarities/differences. That's why I italicized syntax, an attempt to highlight the fact that it wasn't really something to seriously compare with.

The real point of my reply was the request for clarification of what he was asking for, should have left it at that.

bitprophet fucked around with this message at 15:38 on Apr 15, 2008

Wulfeh
Dec 1, 2005

The mmo worth playing: DAoC
I know this is a big vague, but hopefully someone may have an idea

code:
def contact_delete(request, file, contact_id): 
	
	contact_record = Contact
	contact_record = get_object_or_404(Contact, id=contact_id)
	contact_record.delete()
	
	return HttpResponseRedirect('/IR/' + file + '/contacts/')		
this raises an error stating "__init__ takes 2 args, but only 1 is given". I am not sure why/how 2 args are needed for deletion since all the examples show object.delete() as the way to delete

http://dpaste.com/45018/ - Full error message
http://dpaste.com/45019/ - My views, line 100 is the delete part

No Safe Word
Feb 26, 2005

Wulfeh posted:

I know this is a big vague, but hopefully someone may have an idea

code:
def contact_delete(request, file, contact_id): 
	
	contact_record = Contact
	contact_record = get_object_or_404(Contact, id=contact_id)
	contact_record.delete()
	
	return HttpResponseRedirect('/IR/' + file + '/contacts/')		
this raises an error stating "__init__ takes 2 args, but only 1 is given". I am not sure why/how 2 args are needed for deletion since all the examples show object.delete() as the way to delete

http://dpaste.com/45018/ - Full error message
http://dpaste.com/45019/ - My views, line 100 is the delete part

I'm not sure what contact_record = Contact is supposed to be doing, that's assigning the Contact model class to that variable, which then gets clobbered on the next line. It seems like it should possibly work, I don't know what __init__ is missing an arg, because the rest of it looks fine. It's kind of hard to unwind the full debug page dump from that pastebin. A screenshot would be more helpful (to me).

Also, from your views:
code:
		blammo = "SLAMMMOOOOO" #temp - cant do an empty if, but we'll need an if soon
It's funny, but you do know about pass, right? :)

Wulfeh
Dec 1, 2005

The mmo worth playing: DAoC

Wulfeh posted:

I know this is a big vague, but hopefully someone may have an idea

code:
def contact_delete(request, file, contact_id): 
	
	contact_record = Contact
	contact_record = get_object_or_404(Contact, id=contact_id)
	contact_record.delete()
	
	return HttpResponseRedirect('/IR/' + file + '/contacts/')		

Oh woops, contact_record = Contact was left there by accident when I was trying to debug. That can be ignored really.

No Safe Word posted:

Also, from your views:
code:
		blammo = "SLAMMMOOOOO" #temp - cant do an empty if, but we'll need an if soon
It's funny, but you do know about pass, right? :)

I remember passing over that when I started learning Python a few weeks ago, but yea, now it will stick with me since you mentioned it.

ImJasonH
Apr 2, 2004

RAMALAMADINGDONG!
I'm having a problem making my first Django Model class save(). I keep getting an AttributeError with the message: 'Foo' object has no attribute 'id'

The docs make it pretty clear that you don't have to specify an id field, that it'll add one for you if you don't, so what could be keeping it from working?

I'm using a Manager, I have a Meta class that sets a different db_table and an __init__ that sets all the fields, but nothing else that's all that complicated. Any ideas?

Also, I just started using Python last week to play around with the Google App Engine and got hooked on Django this week, it's pretty sweet. Seems to make things just about as easy as possible, I think. Except, of course, when none of your objects will save :(

bitprophet
Jul 22, 2004
Taco Defender

ImJasonH posted:

I'm having a problem making my first Django Model class save(). I keep getting an AttributeError with the message: 'Foo' object has no attribute 'id'

The docs make it pretty clear that you don't have to specify an id field, that it'll add one for you if you don't, so what could be keeping it from working?

I'm using a Manager, I have a Meta class that sets a different db_table and an __init__ that sets all the fields, but nothing else that's all that complicated. Any ideas?

Also, I just started using Python last week to play around with the Google App Engine and got hooked on Django this week, it's pretty sweet. Seems to make things just about as easy as possible, I think. Except, of course, when none of your objects will save :(

Please paste (or pastebin, e.g. dpaste.com) your model code? Hard to troubleshoot without.

Been a while since I tinkered with save() but I am reasonably sure objects do not get an id until after their first save, so depending on what you're doing that might be the issue. Also, "an __init__ that sets all the fields" could be dangerous depending on what that means exactly, which is another reason I'd like to see your code :shobon:

ImJasonH
Apr 2, 2004

RAMALAMADINGDONG!

bitprophet posted:

Please paste (or pastebin, e.g. dpaste.com) your model code? Hard to troubleshoot without.

Been a while since I tinkered with save() but I am reasonably sure objects do not get an id until after their first save, so depending on what you're doing that might be the issue. Also, "an __init__ that sets all the fields" could be dangerous depending on what that means exactly, which is another reason I'd like to see your code :shobon:

http://dpaste.com/45833/

I changed it __init__ to a method, in case that was the problem, and it appears to at least be getting further. Now the problem is:
code:
>>> game = Game()
>>> game.parse_log_line('3.3.1 118 0 1 1 0 11 1 20011024 20011024 1031 Rog Orc Fem Cha jorko,killed by a jackal')
>>> game.save()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Library/Python/2.5/site-packages/django/db/models/base.py", line 238, in save
    ','.join(placeholders)), db_values)
  File "/Library/Python/2.5/site-packages/django/db/backends/util.py", line 12, in execute
    return self.cursor.execute(sql, params)
  File "/Library/Python/2.5/site-packages/django/db/backends/sqlite3/base.py", line 93, in execute
    return Database.Cursor.execute(self, query, params)
InterfaceError: Error binding parameter 15 - probably unsupported type.

deimos
Nov 30, 2006

Forget it man this bat is whack, it's got poobrain!
Try switching the 0 and 1 to true and false, maybe it forgets to do a type check before turning it into a string. Not sure if SQLite shits itself when you try to set a boolean field to 0 or 1.


also what the christ self._aligns.keys().index(chunks[14]) is just self._align[chunks[14]].

deimos fucked around with this message at 21:45 on Apr 19, 2008

ImJasonH
Apr 2, 2004

RAMALAMADINGDONG!

deimos posted:

Try switching the 0 and 1 to true and false, maybe it forgets to do a type check before turning it into a string. Not sure if SQLite shits itself when you try to set a boolean field to 0 or 1.


also what the christ self._aligns.keys().index(chunks[14]) is just self._align[chunks[14]].

Which 0 and 1s? The only boolean field I have is already set with True and False.

_aligns is a dictionary, and I need to store the index of the matching key, not the value of it. It's a dictionary because later on when I output the results I'll want the full value and not the abbreviated one that's in the logs.

ImJasonH fucked around with this message at 22:06 on Apr 19, 2008

deimos
Nov 30, 2006

Forget it man this bat is whack, it's got poobrain!

ImJasonH posted:

Which 0 and 1s? The only boolean field I have is already set with True and False.

_aligns is a dictionary, and I need to store the index of the matching key, not the value of it. It's a dictionary because later on when I output the results I'll want the full value and not the abbreviated one that's in the logs.

Dict key order is not guaranteed between implementations so you might want to rethink that strategem, make it into a multi-dimensional list. There's no need to turn this data into a number when a 3 character string will do, if you want to normalize normalize right but if you're gonna keep your data denormalized at least do so in a legible manner.

I jumped to conclusions with the 0/1 thing.

Try making the fields of a less restrictive type and see (ie. PositiveInteger instead of PositiveSmallInteger) it might be a bug in the backend.

Your code somewhat stinks of SAVAGELY OPTIMIZED overtones.

deimos fucked around with this message at 23:52 on Apr 19, 2008

ImJasonH
Apr 2, 2004

RAMALAMADINGDONG!

deimos posted:

Your code somewhat stinks of SAVAGELY OPTIMIZED overtones.

You're probably right, I could probably save myself a lot of trouble by just storing strings in the database instead of ints. In fact, yeah, I'm going to tweak this some and simplify.

Adbot
ADBOT LOVES YOU

deimos
Nov 30, 2006

Forget it man this bat is whack, it's got poobrain!

ImJasonH posted:

You're probably right, I could probably save myself a lot of trouble by just storing strings in the database instead of ints. In fact, yeah, I'm going to tweak this some and simplify.

I am not against storing ints where ints are due, but making them small or large really isn't saving you a lot. Still I'd love to know if it's some sort of backend issue with django so that a proper ticket can be opened.

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