Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Nov. 26, 2005 15:04:05

p.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Hiding fields in admin interface


Is it possible to hide fields in the admin interface? I want my admin
interface to be able to modify only some fields on an already created
object. I want the fields that aren't displayed to merely stay the
same. However, if I leave the undesired fields out of the fields list,
I get errors when I try to save. I think it blanks those fields out
rather than just leaving them how they were.

Offline

#2 Nov. 27, 2005 00:34:44

oggie r.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Hiding fields in admin interface


Did you try the "editable=False" argument, as in:
class MyModel(meta.Model):
myField = meta.CharField(maxlength=20, editable=False)

Offline

#3 Nov. 27, 2005 17:34:39

p.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Hiding fields in admin interface


I get the same problem with this field. It doesn't show up in the
admin interface, but when I try to save the object, it blanks the field
and tries to update it in the database. Since the field I want hidden
is a foreign key, the update statement dies saying "ERROR: invalid
input syntax for integer."

I can get around this by adding a _pre_save() method, looking up the
old value, and the setting it on the new object. However, this is
pretty messy.

Is there a way to get the field to display on the admin as merely
uneditable text, then? The core of my problem is that the foreign key
field points to a table that is huge (tens of thousands of values).
When the admin page loads, it makes a drop down box with all of these
values. Therefore, the admin page size is really large and it takes a
long time to load. I would rather just show the text of the field or
hide it altogether, without showing a drop down of all the possible
values.

Offline

#4 Nov. 27, 2005 19:10:22

oggie r.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Hiding fields in admin interface


> The core of my problem is that the foreign key
field points to a table that is huge (tens of thousands of values).

Ahh, that makes it much easier! You can put the foreign key in there
with the field argument "raw_id_admin=True". It will be much quicker to
load and much cleaner to use.

class Poll(meta.Model):
huge = meta.ForeignKey(Huge, raw_id_admin=True)

-rob

Offline

#5 Nov. 27, 2005 21:01:47

p.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Hiding fields in admin interface


Thanks, that's really helpful. I missed that argument when I was going
through the docs.

Offline

Board footer

Moderator control

Enjoy the 23rd of April
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support