I used to see the ModelMultipleChoiceField how to set up a custom query; And I do them and they work. However, they all use the same paradigm: the query is a filtered list of only one object.
In my case, I am trying to make the administrator a multilevel form which, instead of using the user names, as part of the text portion of my account class, i name
I would like to use the field.
The breakdown of what I have got:
# models.py class account (models.Model): name = models.CharField (max_length = 128, help_text = "A display name that people understand") user = model. Phoenis (user, unique = True) # Settings.py added for user category in category organization (models.Model): admin = model Many users (users) import django.forms from # admin.py Import the django.contrib.auth.models from ModelMultipleChoiceField User Class OrganisationAdminForm (forms .modelForm): def __init __ (auto, * args, ** kwargs): Import from ethico.accounts.models accounts self.base_fields ["Administrator"] = ModelMultiFollyFixed (Model = Organization
This works, it works, however, I want to draw a selection box with property account.name
property and User.id
above the queryset . It does not work Is:
queryset = Account.objects.all (). Order_by ("name") Values_list ("user", "name")
Failed with this error:
There is no attribute in 'Tupal' object 'PK'
I thought it would be easy, but it was dead -Can change in some hours after the ending. Anybody can take care of highlighting
You can use custom widgets, its can override the render
method here's a tax What I have done for the field:
class UserToAccount (forms.widgets.TextInput): Def Render (self, name, value, strings = none): If the estense (value, user) ): Value = Account.objects.get (user = value) .name Return Super (UserToAccount, self) .render (name, value, attrs = none)
Then of course, use To use your custom widget, the widget
parameter of my admin field I do not know that it can be customized for a select
Can.
Comments
Post a Comment