Hello,
I have problems with significant alteration of admin forms. This project
database is quite complex and inside relationships are not obvious enough
to let Django automatically create usual model admin forms.
On the basis of database, form fields must be generated dynamically, I
cannot know their number in advance. I have eventually solved this by
editing locals() in ModelForm class, it's a dirty way, but it works,
something like this:
#####
class SubjectAdminForm(forms.ModelForm):
for string, label in label_list.iteritems():
locals()['lang_str_%s' % string] = forms.CharField(label = '%s' %
label,widget=forms.TextInput(attrs = {'size':'128'}))
class Meta:
model=Subject
#####
However, this is hard-coded in class object and doesn't allow me to be
flexible. If I, for example, want to set attribute "initial" in a CharField
according to __init__ kwargs arguments, I cannot, because it's called
after. I am in a blind alley.
To sum up, my question is: I need to generate model admin forms dynamically
with advantage of __init__ arguments, I need at least know which item was
just chosen to edit.
Thank you in advance,
Lubos
P.S.: I am a novice in Django and even Python, so I probably use confusing
terms and find roundabouts where elegant ways exist. I will be glad for any
help.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/django-users/-/15qO1mnoBRkJ.
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.