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
king_kilr
May 25, 2007
A note about the OP, you define __str__ in your models, however when you query the db using the api it's attributes are unicode, which I believe means you are using svn, and therefore you should have defined __unicode__ instead, let me know if I'm wrong, either way: yay django, and use trunk :D

Adbot
ADBOT LOVES YOU

king_kilr
May 25, 2007
You can also use select_related() to be more efficient(for example if you have an Entry model that is fkeyed to a Category model, you can use this to get the categories with the entries, that way you won't have an extra query whenever you access the category attr on the entry).

king_kilr
May 25, 2007

ATLbeer posted:

I'm going to be at PyCon next week. If I run into any of the Django guys I'll mention it because I want a shirt that looks decent too.

See you there! Are you sprinting?

king_kilr
May 25, 2007
Who is your shard host? Most of them have their own specific instructions. This thread: http://groups.google.com/group/django-users/browse_thread/thread/68c21aab73d212ff has some good info for the various shared hosts.

king_kilr
May 25, 2007

Neurozys posted:

I'm still just getting my toes wet with web programming, but it looks like Ruby on Rails has some nice shortcuts for using Prototype and script.aculo.us. I've read the B-List articles about doing AJAX with Django from back in fall of '06, but it seems relatively complex. Are there any shortcuts for integrating all that 'Web 2.0' jazz on Django these days, or is it still a mostly manual process requiring a fair amount of javascript coding?

Yes, Django won't write your javascript, it also doesn't lock you into using a specific toolkit, so you can use YUI, Dojo, jQuery, whatever.

king_kilr
May 25, 2007
If you want something similar to Rails' migrations, check out django-evolution: http://code.google.com/p/django-evolution/

king_kilr
May 25, 2007
For anyone who's interested I've been working on building a plugin system for django. It's still a work in progress, but it should work. You can check it out here: http://github.com/alex/django-plugins/tree/master

king_kilr
May 25, 2007
There shouldn't be a question mark after the '/' in admin.

king_kilr
May 25, 2007
Take 50 out of quotes, I'm pretty sure it is try to do this int(str("50")).

king_kilr
May 25, 2007

ATLbeer posted:

I dunno if you posted in the right thread or not but, I'm a bit confused at what your trying to do there

"50" itself is a string. There's no reason to cast it into a string str("50") again.
- "50" == str("50") == True

To cast the string "50" into an integer (as you said 'Take 50 out of quotes') you would just int("50") the str part is redundant.

ashgromnies edited his post :P . My post isn't clear, I meant str("\"50\"")

king_kilr
May 25, 2007

Addict posted:

It looks like I may have a project coming up that deals with Ajax. Not like a metric ton of ajax, but a pretty fair amount. Mostly visual/organization related. Is django solid enough with ajax to still use it, or do I need to consider doing it on rails.

Django has support for many different serializes(JSON, XML, etc.), there is no reason you couldn't use it, on the other hand, it won't right your javascript for you.

king_kilr
May 25, 2007
You seem to be willfully ignoring the fact that this is python, you can write code, if you have to do a task several times write a function, use a loop!

king_kilr
May 25, 2007
You can consult this page: http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges to see any backwards incompatible changes since .96.

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

king_kilr
May 25, 2007

deimos posted:

generally speaking you don't want nulls in tables, it does funky stuff with some queries and generally acts weird depending on implementation.

As to your problem, you also need blank=True. blank controls Admin.

Not for much longer! On This Week in Django(great podcast), Malcom Tredinick(core commiter), said queryset-refactor will be getting merged sometime this week/next week, that branch fixes tons of SQL construction issues(including NULLS, joins, and about a billion other things).

king_kilr
May 25, 2007
And queryset-refactor just hit trunk: http://code.djangoproject.com/changeset/7477 YAY!

king_kilr
May 25, 2007
If you want schema migration I would check out django-evolution(on google code).

king_kilr
May 25, 2007

ATLbeer posted:

I had the same reaction when I started using Django myself. I found myself implementing something that was already built into Django.

For example if you didn't know. You have a model already pre-built. Need a form for that model?

ModelForm = form_from_model(SomeModel)
ModelForm.as_ul()

Poof..

This is no longer the correct way to do it actually, if you are using SVN you should use ModelForms.

king_kilr
May 25, 2007

FrontLine posted:

Can somebody post an example of how to use the validators mentioned at the bottom of http://www.djangoproject.com/documentation/forms/

The one provided isn't to clear, for a newb like me, on the proper usage.

Specifically I have three fields that are only required if the user selects 'Yes' on a BooleanField with the RadioSelect widget. If the user selects or No or selects nothing the fields aren't required.

I'm thinking RequiredIfOtherFieldGiven but prove me wrong :)

Don't use that, you should be using newforms.

And also, for everyone using pretty much any version of django there is a security update to fix an XSS issue in the Admin, more info on the django blog.

king_kilr
May 25, 2007
I'd usually do that in the __init__ method, rather than in the view.

[code]
class SampleForm(forms.Form):
field = forms.ModelChoiceField(queryset=Model.objects.none())
def __init__(self, *args, **kwargs):
user = kwargs.pop('user')
super(SampleForm, self).__init__(*args, **kwargs)
self.fields['field'].queryset = Model.objects.filter(owner=user)

king_kilr
May 25, 2007
I'd usually do that in the __init__ method, rather than in the view.

for example:
code:
class SampleForm(forms.Form):
    field = forms.ModelChoiceField(queryset=Model.objects.none())
    def __init__(self, *args, **kwargs):
        user = kwargs.pop('user')
        super(SampleForm, self).__init__(*args, **kwargs)
        self.fields['field'].queryset = Model.objects.filter(owner=user)

king_kilr
May 25, 2007
It's not documented because it's considered internals, my guess is it's that way because sometimes DRY and explicit bump heads.

king_kilr
May 25, 2007
This query will probably be pretty slow but what you can do is:

code:
import operator
def search(request):
    query = request.GET.get('q', '')
    q = reduce(operator.or_, [Q(english__icontains=i) for i in query])
    Model.objects.filter(q)
What this does is it creates a Q object for each letter, and then ors them together.

king_kilr
May 25, 2007
As some of you may know, Django Dash(http://www.djangodash.com/) will be occuring next weekend, and registration ends today. Is there anyone who would be interested in working on something with me. I have no idea for a project(or at least no original ones :P). If you are interested either let me know here, or message me in the #django channel on freenode IRC(my name is the only one that starts with Alex_ in the channel).

king_kilr
May 25, 2007
Checkout django-wikiapp it keep revisions for all the articles, theres also django-rcsfield.

king_kilr
May 25, 2007
Checkout django-wikiapp it keep revisions for all the articles, theres also django-rcsfield.

king_kilr
May 25, 2007
Checkout django-wikiapp it keep revisions for all the articles, theres also django-rcsfield.

king_kilr
May 25, 2007
Correct, select_related() only goes forward at present, there was some discussion a while ago about having it work backwards as well, and malcolm said he would probably look at it, and that it was doable.

king_kilr
May 25, 2007
Correct, select_related() only goes forward at present, there was some discussion a while ago about having it work backwards as well, and malcolm said he would probably look at it, and that it was doable.

king_kilr
May 25, 2007
You can still do backwards relations: http://www.djangoproject.com/documentation/db-api/#backward you just can't use select_related to prefect them

king_kilr
May 25, 2007
Yes, someone could attack you by uploading a huge image(it will get read into memory), check out ticket #2070.

king_kilr
May 25, 2007
You are putting a form field on a model.

king_kilr
May 25, 2007

chocojosh posted:

1) Is Django an appropriate tool?
2) Any major differences between Django and rails?
3) How much Python do I need to know for Django? I've spent a few days looking into pygame and wrote a few hundred lines of code but I'm not familliar with "the python way" of doing things.
4) How long will it take me "to get up to speed" with Django?
5) Any deployment issues I should be aware about with her webhost? Their site says they support python. Do they need to add extra modules for Django?
6) Any warnings/gotchas I should know about?


1) Yes
2) Probably, I don't know much about rails
3) You'll learn quickly enough :D
4) Not terribly long
5) Maybe, if it's shared hosting you might have a problem, check out http://djangofriendly.com/hosts/ for hosting reviews
6) Go use satchmo: http://www.satchmoproject.com/

king_kilr
May 25, 2007

Bonus posted:

1.0 is supposed to come out on September the 2nd. Read more about the schedule here

There's also this nice wiki page: http://code.djangoproject.com/wiki/VersionOneRoadmap

king_kilr
May 25, 2007

ATLbeer posted:

Followed by rewriting all your models.py files :\

It's a great change just breaks a lot.

There's a snippet on djangosnippets that tries to automate creating the new admin.py files.

king_kilr
May 25, 2007
Here's the inline stuff: http://www.djangoproject.com/documentation/admin/#inlinemodeladmin-objects

king_kilr
May 25, 2007
And ticket 5361 just hit, this allows for using alternate file system backends, yay!

king_kilr
May 25, 2007
If anyone is interested I have a django application(open source, BSD license) for doing ajax validation for your forms(ie, you have a form and want to be able to validate in over ajax using the form classes you already created in python). You can check it out at http://github.com/alex/django-ajax-validation/tree/master if you use git or http://code.google.com/p/django-ajax-validation/ if you use SVN.

king_kilr
May 25, 2007
new docs stuff just hit django, you can check out the hotness at http://docs.djangoproject.com/

Adbot
ADBOT LOVES YOU

king_kilr
May 25, 2007

mwarkentin posted:

Thought I'd bump this for RC1! http://www.djangoproject.com/weblog/2008/sep/02/10-rc1/

Also, I've got a question regarding payment gateways.. I need to integrate one into a project I'm working on.. are there any out there that I can just plug in?

What's the easiest to integrate with? Paypal? Authorize.net?

Pros & cons?

I don't know about the pros and cons of each but satchmo(django store app)(satchmoproject.com) has a ton of support for various gateways built in, so you can probably steal code from them for whatever you are working on.

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