Wednesday, August 11, 2010

Django - Utilities for a beginner

In this post I recopile useful information I have found when looking for help.

  • How to specify a multiple field primary key? It is complicated, but what we can do is to specify a set of fields to be unique in the meta class of our model.
http://stackoverflow.com/questions/1624257/django-or-similar-for-composite-primary-keys
http://docs.djangoproject.com/en/dev/ref/models/options/#unique-together
  • Dynamic Django Queries
http://www.nomadjourney.com/2009/04/dynamic-django-queries-with-kwargs/

  • How can I make request.session parameters visible to a template without passing them as a parameter?
http://stackoverflow.com/questions/335231/in-django-is-it-possible-to-access-the-current-user-session-from-within-a-custom

  • A good way to customize templates for visualizing forms and form errors:
http://mikepk.com/2010/08/python_django_forms_errors_fieldsets/

  • A free online book which explains Django:
http://www.djangobook.com/

  • How to navigate in a template in a one-to-many relation:
http://solutions.treypiepmeier.com/2009/01/21/one-to-many-or-many-to-many-relationships-in-django-templates/

  • A tutorial to build a first application in Django, in four steps:
http://docs.djangoproject.com/en/dev/intro/tutorial01/

  • Query sets in Django. How can we use a field of a related object inside a filter? With object1.filter(obect2__field="aaa")
http://stackoverflow.com/questions/1086341/help-with-django-querysets

  • A person who gave up Django explains its reasons:
http://groups.google.com/group/django-users/browse_thread/thread/394701c83497e405?pli=1

  • The Catalan Django group:
http://groups.google.com/group/django-cat

  • A Django users Google Groups group
http://groups.google.com/group/django-users

  • A comparison of CMSApplications for Django
http://code.djangoproject.com/wiki/CMSAppsComparison

  • How to pass initial values to a form without validating it?
http://stackoverflow.com/questions/1882616/pass-an-initial-value-to-a-django-form-field

The general explanation of form fields is here:
http://docs.djangoproject.com/en/dev/ref/forms/fields/

  • Where can we host our Django application? A list of the most popular webs and its prices:
http://code.djangoproject.com/wiki/DjangoFriendlyWebHosts

  • Using reverse() in HttpResponseRedirect to avoid having to hardcode a URL in the view function:
http://adil.2scomplement.com/2009/01/django-using-reverse-instead-of-hardcoded-urls/

  • Changing the Model Choice Field Queryset:
from django import newforms as forms
from django.contrib.auth.models import User

class ComplaintForm(forms.Form):
user = forms.ModelChoiceField(queryset=User.objects.none())
message = forms.CharField(widget=forms.Textarea())

def __init__(self, *args, **kwargs):
super(ComplaintForm, self).__init__(*args, **kwargs)
self.fields["user"].queryset = User.objects.filter(is_staff=False)

http://oebfare.com/blog/2008/feb/23/changing-modelchoicefield-queryset/

  • Official documentation about generic views
http://docs.djangoproject.com/en/1.2/ref/generic-views/

No comments:

Post a Comment