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
Why are you creating the join table yourself instead of just using a ManyToManyField?

EDIT: If the reason you are doing it is to add extra fields to the join table look at the through kwarg on M2M Fields.

Adbot
ADBOT LOVES YOU

king_kilr
May 25, 2007
Also, it should br primary_key = True; not 'True', one is a string, the other is a bool.

king_kilr
May 25, 2007
DjangoCon videos are starting to come out: http://www.youtube.com/results?search_query=djangocon&search=tag

king_kilr
May 25, 2007
Django doesn't have "negative filters" so there is no not equal filter, or not in, you just use excluse instead of filter.

king_kilr
May 25, 2007

Munkeymon posted:

I'm trying to add content from the blog app in my project to templates rendered by the main project and I don't think I'm doing it the best way. Right now, I have a view on the main app calling a view on the blog that renders a post using a template and returns the result wich I dump into the main page context. My concern is that the blog post is being rendered whether or not it is being displayed, but I don't know of a better way to do this and keep the template under the control of the blog app which (as I see it) is where it belongs.

I would do an inclusion tag(look for that in the doc), or do something like this: http://www.b-list.org/weblog/2006/jun/07/django-tips-write-better-template-tags/

king_kilr
May 25, 2007

nbv4 posted:

I've been developing a PHP webapp for the past year or so. It's working fine right now, but when I started the project, I didn't really know that much about web development, so it didn't get a very good foundation to start on. A year later, everything works, but the code is a clusterfuck. There are certain things I'd like to change about my app, but since the code is so unorganized, it'll take forever.

I decided my best course of action is to just start over, this time with a framework of some kind to make sure I don't get the project off on the wrong foot. I've decided on Django, but it's hard because every tutorial out there seems to focus on how to use each individual tool of Django, rather that giving you an idea of how the whole system should work project wide. In other words, they all seem to be written as if Django was a language, rather than a framework.

I'm looking for a more "top down" understanding of Django. Something like a tutorial that takes a large project, and breaks all the parts down, instead of a tutorial that starts with nothing, and ends up with a project. Does such a tutorial exist? Does anyone know of a large project that exists where the source is available so that I can look through it?

I'd check out James Bennet's Practical Django projects, the code is NOT fully up to date with 1.0, but most of it will work unchanged, and it does exactly what you want.

king_kilr
May 25, 2007

bitprophet posted:

Guess it depends on what exactly you need to do with those values on the query side of things, but it could be an OK choice, nothing obviously wrong with it that I can see.


Also, hooray! the book is officially out. Got my hard copies last night. Here's a crappy iPhone photo:


Congrats! How is pbx doing? I remember hearing he was in a bad car accident over the summer.

king_kilr
May 25, 2007
Just looked through the index for your book, and I have to say the examples sound really cool, I can't wait to check it out.

king_kilr
May 25, 2007
Just started blogging(thanks to a bunch of Django people for yelling at me), here's my first post: http://lazypython.blogspot.com/2008/11/lazy-user-foreign-keysthis-is-double.html

Let me know what you guys think.

king_kilr
May 25, 2007

Wulfeh posted:

I was under the impression that class Meta ordering was "bad", something to do with inheritance, I forget. It was something mentioned by David Cramer at djangocon. Does anyone remember the exact reason why?

If I recall correctly he was running into something where it was lreading to ordering a huge dataset where it wasn't necessary.

king_kilr
May 25, 2007
FYI, reverse often appears slow, but it's cached, so it's not a big performance issue(compared to all the other things that can be slow in a request).

king_kilr
May 25, 2007
I think you mean to be using model formset factory, instead of formset factory.

king_kilr
May 25, 2007

WickedMetalHead posted:

Does unique_for_month still work?

I tried having a BooleanField set with unique_for_month="date" and also a CharField with choices and null/blank = True set to unique_for_month="date" and in both cases it allowed me to check the field twice or pick a choice twice.

Right now, in model forms, the only thing that's validated is unique, and unique together(I'm the guy who wrote that). Properly validating for everything isn't going to happen until 1.1, when ticket #6845 get's fixed, that ticket is model validation, and amongst other things it will handle propogating all validation on the model to the form level.

king_kilr
May 25, 2007

nbv4 posted:

Does anyone have any experience using django-tagging with django 1.0? Is it stable? or alternatively a tagging system that works well with 1.0?

yeah it should work fine, you need to use the newforms-admin branch though.

king_kilr
May 25, 2007

bitprophet posted:

:confused: Is there some sort of neo-newforms-admin that continues to exist/be relevant post-1.0?

Not nfa within django itself, but the nfa branch on django-tagging, it just hasn't been updated yet I guess.

king_kilr
May 25, 2007

Murodese posted:

How do I stop recursive foreign keys from being able to choose themselves? I don't want a category to be able to pick itself as its parent :V

I'd just create a custom model form for use in the admin and elsewhere that has a clean_<my_fkey> method which throws a validation error if cleaned_data['my_fkey'] == self.model.id

king_kilr
May 25, 2007
To the gentleman who wanted to have a view that combined querysets of different types that had a few common fields, I wrote a blog post about it today, hope it's helpful, here

king_kilr
May 25, 2007

No Safe Word posted:

So Adrian and company are working on an updated Django Book, and the work-in-progress is online for everyone to see like last time, yay!

http://www.djangobook.com/en/2.0/

(Django Book 2.0 covers Django 1.0 :mmmhmm: )

James Bennet also announced(officially) that he's working on a 2.0 of Practical Django Projects.

Also, for those who haven't been following 1.1, there is going to be a crapton of new, awesome, stuff, I've been helping out with some of it and it's going to be awesome

king_kilr
May 25, 2007
Well aggregation is really nice, I love the API on it. Model validation is going to be a huge boon for people who want it just because there wasn't an easy workaround for those that needed it before(you could always write raw SQL). Plus bulk-editing stuff on the changelist actually looks great and can be a huge help for what should be simple tasks(for example making a BooleanField editable from there and just using it to enable stuff en masse).

Of course I've been following all of these, coded 1 myself, and provided a bit of assistance on the others, so I might be biased :)

king_kilr
May 25, 2007

mwarkentin posted:

Any idea if the read-only admin fields are going to make it in?

Possible, it's already possible to do in your own code though: http://lazypython.blogspot.com/2008/12/building-read-only-field-in-django.html

king_kilr
May 25, 2007
FYI aggregates: http://code.djangoproject.com/changeset/9742

king_kilr
May 25, 2007
For those who are interested EuroDjangoCon registration is now open here: http://euro.djangocon.org/ . I've submitted a talk proposal on some advanced forms techniques.

king_kilr
May 25, 2007
2 pieces to the puzzle, 1 a management command for the script itself, 2 python lockfile for the lock: http://pypi.python.org/pypi/lockfile

king_kilr
May 25, 2007

deimos posted:

As a sidenote, what's the state of django on Windows? I haven't tried it at all. I need to connect to SQL Server and last I checked the only reliable way was running django on Windows through Apache and :downs: mod_python.

On the MSSQL front django-pyodbc and django-mssql are both decent, though I don't know which is actually better.

king_kilr
May 25, 2007

Mashi posted:

Anyone got any recomendations for database schema migration tools for Django? Anyone use and are happy with it? I'm talking about the sort of tool that allows me to type "manage.py evolvedb" and it will print SQL to sync the differences between the models and the DB structure.

I like django-evolution: http://code.google.com/p/django-evolution/
south is also popular: http://south.aeracode.org/

king_kilr
May 25, 2007
code:
{% for prods in prodlist %}

<div>
{{ prods.name }}
</div>

{% if forloop.counter|divisibleby:"3" %}
<br />
{% endif %}

{% endfor %}

should do what you want

king_kilr
May 25, 2007

bitprophet posted:

Sorry...it does :( it's actually just 376 pages of bad slash fanfiction starring Django Reinhardt and his pet snake.

(Not really. It's not The Best Book Ever, there's a lot of things I wish we'd had time to do differently or go into more detail on, but I think we did a relatively good job with it given there were 3 authors without a lot of time on our hands.)

Somehow I imagine m0nk3yz jumping straight up to Marty's book within a week.

king_kilr
May 25, 2007

m0nk3yz posted:

Also, if anyone knows anyone, I'm looking for a senior-or-higher level web person, preferably someone with Django experience. (in MA)

You could try luring Doug Napoleone away from his job, I don't think he gets to do Python by day :)

king_kilr
May 25, 2007

Ansible posted:

Wow, I love Django already. Never programmed in Python before, but was able to setup a linux VM and blow through the OP in under two hours. There are a few changes besides __unicode__ in 1.0 but they weren't a big deal.

Be sure to read the official docs/tutorial, they really are great :)(I feel like I say this alot).

king_kilr
May 25, 2007

Lamacq posted:

Wait, what? I am a django newb and for my first app I've been using render_to_response() b/c that's what the tutorial does. I'll go back to the docs again (I've been spending a LOT of time with the django docs over the past couple weeks) and look for that stuff, but can you give me the 30 second elevator pitch on why I should use template.render(context) and what are context_processors??

Thanks

You're fine using render_to_response I think he meant it in the reverse. context processors are basically a way to have a "global" template variable. So say you want a logic form on every page you could put it in a template context processor so every single view didn't have to provide it.

king_kilr
May 25, 2007

No Safe Word posted:

And I could have sworn there was some sort of RequestContext middleware that either shipped with Django at some point or was on their code.djangoproject.com wiki somewhere that did this for every response automatically but I'll be damned if I can't find it. I don't want to reimplement it half-assed if it's already out there, but I can.

Are you takling about this: http://www.djangosnippets.org/snippets/3/

king_kilr
May 25, 2007

Ansible posted:

There was a few other differences as well, such as the new admin.py, maxlength renamed to max_length and prepopulated fields being defined in admin.py

I believe we have a full listing here: http://docs.djangoproject.com/en/dev/releases/1.0/

king_kilr
May 25, 2007

Ansible posted:

Yup that is what I used.

Started playing with Forms this weekend, I love it.

For my overly ambitious webapp I am going to want an interface similar to mint.com's Transaction view, where it lists a series of items associated with the user and they can edit their attributes inline. Would django+AJAX be a workable way to do this or should I use another frontend? I say AJAX because I would prefer that the page doesn't reload when an edit is submitted or I could use straight django.

Yep, and if it's editing multiple models of the same type there take a look at formsets.

king_kilr
May 25, 2007

duck monster posted:

Keep in mind the relational stuff does, as far as I'm aware, the joins at the python side rather than the mysql side.

Is there a way to use views as a back-end to a model to force the joins to operate smoothly at the mysql side

What? There's just no basis for what you just said. Django preforms normal SQL queries with joins.

If you want to use views you can use the new managed option on models.

king_kilr
May 25, 2007

bitprophet posted:

Well, as king_kilr said, check out the new 'managed' option for models:

http://docs.djangoproject.com/en/dev/ref/models/options/#managed

It'll let you ensure that Django won't even try to update that particular DB table, meaning you can actually use SQL views and not worry about errors (which, prior to now, would crop up when you do e.g. manage.py syncdb -- it'd try to create or modify your SQL view, which of course would raise a database error).

The feature is in trunk and I believe it'll be part of the 1.1 release; king_kilr pays closer attention than I do and can confirm/deny that.

Indeed, anything in trunk makes it's way into the release. The Django policy isn't to branch for a release after feature freeze, it's to wait until the the release is done before committing any new features.

king_kilr
May 25, 2007
Write a template filter/tag to let you do simple operations on a queryset in the template will be the easiest way.

king_kilr
May 25, 2007
if the issue is not having a django settings file you can always do:

from django.conf import settings
settings.configure(MY_SETTING=value, OTHER_SETTING=value)

To set up the right settings for there, because what you're seeing is django's internationalizating framework, you can probably coerce them to strings with just:

settings.configure(USE_I18N=False)

king_kilr
May 25, 2007

Ansible posted:

I agree. Is there a good source for best practices in django development? My entire site is just one app, but I'm considering splitting it up into functional areas based on related tables/models.


Flot looks pretty cool, I'll play with that over the weekend.

Read anything james bennet writes(see his DjangoCon video on youtube on reusable applications) his look, Practical Django Development is also good.

king_kilr
May 25, 2007

Mashi posted:

Anyone have a preferred method for storing additional profile data against users? Using a user profile makes the account creation / editing forms a bit messy. Anyone had success subclassing User, or know a nice way to do the forms for a User with a custom profile?

Just use a user profile model, that's how it's done. Needing to hook up a signal reciever and handle 2 ModelForm's isn't difficult, it's like 10 lines of code.

Adbot
ADBOT LOVES YOU

king_kilr
May 25, 2007

m0nk3yz posted:

Man if only we had an example

Yes, if only

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