Unsorted user selection widget after changeset 7806 (nfa)

104 visualizações
Pular para a primeira mensagem não lida

spacetaxi

não lida,
3 de jul. de 2008, 07:56:1403/07/2008
para Django users
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...)
-----

Everything was fine up to changeset 7806, which removed the default
ordering of the User class:
http://code.djangoproject.com/changeset/7806

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?

BTW, I'm using the newforms-admin branch.

TIA
-Stephan

spacetaxi

não lida,
4 de jul. de 2008, 09:21:4604/07/2008
para Django users
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

Karen Tracey

não lida,
4 de jul. de 2008, 09:52:4704/07/2008
para django...@googlegroups.com
On Fri, Jul 4, 2008 at 9:21 AM, spacetaxi <spac...@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.

Karen
 

spacetaxi

não lida,
4 de jul. de 2008, 10:24:2104/07/2008
para Django users
On 4 Jul., 15:52, "Karen Tracey" <kmtra...@gmail.com> wrote:
> You've waited one day right at the beginning of a big holiday weekend in the
> US; [...]

Ooops, sorry. I didn't think about this. Thanks for your feedback!

-Stephan

spacetaxi

não lida,
24 de jul. de 2008, 03:22:4924/07/2008
para Django users
On 3 Jul., 13:56, spacetaxi <spacet...@gmail.com> wrote:
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. ;-)

Kind regards
-Stephan

PS: This also applies to http://groups.google.com/group/django-users/msg/8193091b10d039c9

spacetaxi

não lida,
24 de jul. de 2008, 04:03:3124/07/2008
para Django users
Ooops, I made a little mistake (copy&paste... *g*):

On 24 Jul., 09:22, spacetaxi <spacet...@gmail.com> wrote:
> -----
> class ArticleAdmin(admin.ModelAdmin):
>     def get_form(self, request, obj=None):
> f = super(CVAdmin, self).get_form(request, obj)

The above line must look like this:
f = super(ArticleAdmin, 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)
> -----

Kind regards
-Stephan
Responder a todos
Responder ao autor
Encaminhar
0 nova mensagem