2008/10/2 Jarek Zgoda <[EMAIL PROTECTED]>:
> Anyway, I seem to be unable to change ordering of FKs relating to User
> object. Any hint?
So, suppose you have the following model, a simple user profile:
from django.contrib.auth.models import User
from django.db import models
class UserProfile(models.Model):
likes_spam = models.BooleanField
twitter_username = models.CharField(max_length=255)
website = models.URLField()
user = models.ForeignKey(User)
And suppose you want the list of users, in the admin, to be
alphabetized by username. In your admin.py file, you'd do:
from django.contrib import admin
from django.contrib.auth.models import User
from django import forms
from yourapp.models import UserProfile
class UserProfileForm(forms.ModelForm):
user = forms.ModelChoiceField(queryset=User.objects.order_by('username'))
class Meta:
model = UserProfile
class UserProfileAdmin(admin.ModelAdmin):
form = UserProfileForm
admin.site.register(UserProfile, UserProfileAdmin)
There are other ways to come at this if you just want to override a
single field, but I'm a fan of just doing the form.
--
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---