I am trying to make a simple form, that conditionally shows the
"website" input field based on the value of another database field
(that is not on the form) "status". For the sake of this process the
"status" field is not editable by the user, just by the admin. Both
fields are in the same table: "profile".
After working at this for a while I copped-out and just did the
conditional hiding and showing on the template. But, I realise this
is the unsophisticated method, and would like to improve it.
What I tried so far in forms.py:
class WebsiteForm(forms.ModelForm):
class Meta:
model = Profile
fields = ( 'e-mail', 'website', )
if Profile.status == 'personal' :
exclude = ('website',)
This method in forms.py works effectively, in that I can
conditionally show and hide the field if I use test comparitors in
the if statement like:
if 1 == 1:
or
if 1 != 1:
But, I cannot get an effective test using the field "Profile.status",
the value in the field seems to be unavailable at the point the "if"
test in forms.py is performed.
If I use "print(Profile.status)" I get the following output in the
terminal: "user__profile__status__isnull", so I think this means that
I am at least testing the correct field in the database. Although I
am also noting that this output only shows at initialisation of
"runserver", not when the form page is accessed.
One final point, the user is authenticated and editing their own record.
Any help very much appreciated.
-- Clive
--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/99ABE658-5CF2-4EB3-8E96-6AD2D32CB34B%40indx.co.uk.