Hello, currently I'm a little bit lost on this one... Maybe some kind
soul can give me a hint?
Look at this excerpt of a model class:
-----
from django.db import models
from django.contrib.auth.models import User
class Article(models.Model):
# (...snip...)
editors = models.ManyToManyField(User,
related_name='articles_from_editor')
# (...snip...)
-----
After changeset 7806 the user selection widget in the admin form for
my Article class contains *unsorted* usernames. This is a major
problem when there are a lot of users existing in the database...
So what's the easiest and most elegant way to get the user selection
widget sorted again?
Hm, it seems to me that nobody has a solution? Do I have to replace
the many-to-many-relation (editors) with an additional ArticleEditor-
class, containting a one-to-many relation to the User class and a one-
to-many relation to Article? Is this the only way to get a sorted User
selection widget?
Kind regards
-Stephan
On 3 Jul., 13:56, spacetaxi <spacet...@gmail.com> wrote:
> After changeset 7806 the user selection widget in the admin form for
> my Article class contains *unsorted* usernames. This is a major
> problem when there are a lot of users existing in the database...
> So what's the easiest and most elegant way to get the user selection
> widget sorted again?
On Fri, Jul 4, 2008 at 9:21 AM, spacetaxi <spacet...@gmail.com> wrote: > Hm, it seems to me that nobody has a solution? Do I have to replace > the many-to-many-relation (editors) with an additional ArticleEditor- > class, containting a one-to-many relation to the User class and a one- > to-many relation to Article? Is this the only way to get a sorted User > selection widget?
You've waited one day right at the beginning of a big holiday weekend in the US; I'd guess rather that no one has had a chance to look into this yet. If you want to make sure it doesn't get lost, open a ticket for it, but it's a bit early I think to be concluding you need to restructure your application to get around the change.
> On 3 Jul., 13:56, spacetaxi <spacet...@gmail.com> wrote: > > Hello, currently I'm a little bit lost on this one... Maybe some kind > > soul can give me a hint?
> > Look at this excerpt of a model class:
> > ----- > > from django.db import models > > from django.contrib.auth.models import User > > class Article(models.Model): > > # (...snip...) > > editors = models.ManyToManyField(User, > > related_name='articles_from_editor') > > # (...snip...) > > -----
> > After changeset 7806 the user selection widget in the admin form for > > my Article class contains *unsorted* usernames. This is a major > > problem when there are a lot of users existing in the database...
> > So what's the easiest and most elegant way to get the user selection > > widget sorted again?
> After changeset 7806 the user selection widget in the admin form for
> my Article class contains *unsorted* usernames. This is a major
> problem when there are a lot of users existing in the database...
> So what's the easiest and most elegant way to get the user selection
> widget sorted again?
As I didn't get any feedback on this one, I finally managed to find a
solution on my own. Maybe it'll be helpful for somebody out there.
I define an ArticleAdmin class (newforms-admin) overriding the
get_form method:
-----
class ArticleAdmin(admin.ModelAdmin):
def get_form(self, request, obj=None):
f = super(CVAdmin, self).get_form(request, obj)
qs = f.base_fields['editors'].queryset
f.base_fields['editors'].queryset = qs.order_by('username')
return f
admin.site.register(Article, ArticleAdmin)
-----
I don't know if this is the best possible solution... but it
works. ;-)