Discussion:
Hidden field in Admin without label
PierreR
2009-05-06 14:48:05 UTC
Permalink
I don't seem to find a good way to have a hidden field in the admin
console. I can of course get the hidden field easily but the label is
still showing up. This problem is really related to the Admin app.

I have been trying to "hack" the "fieldset.html" but it is not that
easy. "is_hidden" is only available on field.field ...

The best solution is probably to get the hidden fields to go in a
different fieldset (admin wise) so I can apply a style on the fieldset
level, not on the fieldlevel.

The following solution will not work if I need to mark as hidden a
field of a base class:

http://groups.google.com/group/django-users/browse_thread/thread/10fd33e509255b4b/0f102501bfccb93c?lnk=gst&q=hidden+field+admin#0f102501bfccb93c

Any idea ? Thanks very much.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
Daniel Roseman
2009-05-06 15:24:17 UTC
Permalink
Post by PierreR
I don't seem to find a good way to have a hidden field in the admin
console. I can of course get the hidden field easily but the label is
still showing up. This problem is really related to the Admin app.
I have been trying to "hack" the "fieldset.html" but it is not that
easy. "is_hidden" is only available on field.field ...
The best solution is probably to get the hidden fields to go in a
different fieldset (admin wise) so I can apply a style on the fieldset
level, not on the fieldlevel.
The following solution will not work if I need to mark as hidden a
http://groups.google.com/group/django-users/browse_thread/thread/10fd...
Any idea ? Thanks very much.
The best way to do this is to define a custom modelform for your admin
class, and override the definition of your field there to make it use
a HiddenInput widget.

class MyForm(forms.ModelForm):
myfield = forms.CharField(widget=forms.HiddenInput)
class Meta:
model = MyModel

class MyAdmin(admin.ModelAdmin):
form = MyForm

admin.site.register(MyModel, MyAdmin)
--
DR.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
PierreR
2009-05-07 07:23:17 UTC
Permalink
That is what I do !
(another way is to define a custom model field and override the
"formfield" method).

But ... I cannot get rid off the label in the admin console. That is
my problem.

Any easy way to remove the label of an hidden field in the admin
console ?

Thanks.
Post by Daniel Roseman
Post by PierreR
I don't seem to find a good way to have a hidden field in the admin
console. I can of course get the hidden field easily but the label is
still showing up. This problem is really related to the Admin app.
I have been trying to "hack" the "fieldset.html" but it is not that
easy. "is_hidden" is only available on field.field ...
The best solution is probably to get the hidden fields to go in a
different fieldset (admin wise) so I can apply a style on the fieldset
level, not on the fieldlevel.
The following solution will not work if I need to mark as hidden a
http://groups.google.com/group/django-users/browse_thread/thread/10fd...
Any idea ? Thanks very much.
The best way to do this is to define a custom modelform for your admin
class, and override the definition of your field there to make it use
a  HiddenInput widget.
    myfield = forms.CharField(widget=forms.HiddenInput)
        model = MyModel
    form = MyForm
admin.site.register(MyModel, MyAdmin)
--
DR.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
PierreR
2009-05-07 08:35:57 UTC
Permalink
Well so far the only "not so ugly way" (in the sense that it is only
one line of code) I have found to do this is to change the css
directly (in my case admin.css):
/* Hacky way to remove hidden field lavel in the Admin console */
div.form-row.last_modified { display: none;}
Post by PierreR
That is what I do !
(another way is to define a custom model field and override the
"formfield" method).
But ... I cannot get rid off the label in the admin console. That is
my problem.
Any easy way to remove the label of an hidden field in the admin
console ?
Thanks.
Post by Daniel Roseman
Post by PierreR
I don't seem to find a good way to have a hidden field in the admin
console. I can of course get the hidden field easily but the label is
still showing up. This problem is really related to the Admin app.
I have been trying to "hack" the "fieldset.html" but it is not that
easy. "is_hidden" is only available on field.field ...
The best solution is probably to get the hidden fields to go in a
different fieldset (admin wise) so I can apply a style on the fieldset
level, not on the fieldlevel.
The following solution will not work if I need to mark as hidden a
http://groups.google.com/group/django-users/browse_thread/thread/10fd...
Any idea ? Thanks very much.
The best way to do this is to define a custom modelform for your admin
class, and override the definition of your field there to make it use
a  HiddenInput widget.
    myfield = forms.CharField(widget=forms.HiddenInput)
        model = MyModel
    form = MyForm
admin.site.register(MyModel, MyAdmin)
--
DR.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
Daniel Roseman
2009-05-07 08:37:53 UTC
Permalink
Post by PierreR
That is what I do !
(another way is to define a custom model field and override the
"formfield" method).
But ... I cannot get rid off the label in the admin console. That is
my problem.
Any easy way to remove the label of an hidden field in the admin
console ?
Thanks.
Hmm. Does the field need to be in the form at all? You could just add
it to the 'exclude' tuple in the ModelAdmin declaration, then it won't
show up.
--
DR.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
PierreR
2009-05-07 09:01:12 UTC
Permalink
Thanks for your reply.

My intention is to use this field as a version/timestamp to implement
a form of optimistic locking. I need to receive it back from the user
through a form and check it against the current version/timestamp of
the updated record.

I don't think "exclude" will work for me.
Post by Daniel Roseman
Hmm. Does the field need to be in the form at all? You could just add
it to the 'exclude' tuple in the ModelAdmin declaration, then it won't
show up.
--
DR.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
Andy
2009-05-07 10:53:30 UTC
Permalink
Hello Pierre.

I recently came across the exact same problem (and for the exact same
reason)

I don't think my solution was any less ugly that yours. I modified
fieldset.html to look for a specific fieldset name. Anything in that
fieldset is displayed in a manner which honors the hidden field
property.

(so still a hack!)

Andy
Post by PierreR
Thanks for your reply.
My intention is to use this field as a version/timestamp to implement
a form of optimistic locking. I need to receive it back from the user
through a form and check it against the current version/timestamp of
the updated record.
I don't think "exclude" will work for me.
Post by Daniel Roseman
Hmm. Does the field need to be in the form at all? You could just add
it to the 'exclude' tuple in the ModelAdmin declaration, then it won't
show up.
--
DR.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
PierreR
2009-05-11 08:25:00 UTC
Permalink
Thanks Andy,

I don't know if there is a good way to do this without hacking the
admin too much. I have been trying to get all hidden fields in a
separate fieldset which seem more in line with the "fieldset"
philosophy. I have created an __init__ method in my custom admin
class (the one that extends ModelAdmin). At the end, it was not so
easy to get a right filter while processing "model._meta.fields" in
order to dynamically create the fieldset. I have given up considering
that the css hack was good enough.

I am a bit puzzled by the fact that the admin app does not seem to
respect or use the generic django form method (as_table, ...) to
display labels and fields. All the fieldset mechanism is specific to
the admin app and looks kind of awkward to me (it does not support
inheritance). Maybe some historic reasons ?
Post by Andy
Hello Pierre.
I recently came across the exact same problem (and for the exact same
reason)
I don't think my solution was any less ugly that yours. I modified
fieldset.html to look for a specific fieldset name. Anything in that
fieldset is displayed in a manner which honors the hidden field
property.
(so still a hack!)
Andy
Post by PierreR
Thanks for your reply.
My intention is to use this field as a version/timestamp to implement
a form of optimistic locking. I need to receive it back from the user
through a form and check it against the current version/timestamp of
the updated record.
I don't think "exclude" will work for me.
Post by Daniel Roseman
Hmm. Does the field need to be in the form at all? You could just add
it to the 'exclude' tuple in the ModelAdmin declaration, then it won't
show up.
--
DR.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Continue reading on narkive:
Loading...