admin page doesn't auto-refresh

108 views
Skip to first unread message

ledzgio

unread,
Jun 26, 2012, 5:15:07 AM6/26/12
to django...@googlegroups.com
Hi,

I have a problemi with the admin page. In my admin page I have 3 fields that refers to the same table called Team: when I want to add a new Team by pressint the green "+" button, the popoup shows up and I can fill the form and adding a new Team. When I click save, the pop up disappears and I have the new value close to the "+" button I have pressed upon. But the problem is that the other fields that refers to the table Team in the page are empty, so I have to refresh the page in order to see the just added Team show.

How can I fix this behavior?

thanks

Melvyn Sopacua

unread,
Jun 26, 2012, 3:08:11 PM6/26/12
to django...@googlegroups.com
You can't. You should fix your models or use an InlineAdminModel. It
sounds like you're duplicating fields from the foreign key table Team in
other parts of the model.
Either that, or you're using both an InlineAdminModel and have the
foreign key available in admin model.

Without seeing the model definitions and the admin model definitions, we
can only guess.

--
Melvyn Sopacua


Matt Schinckel

unread,
Jun 27, 2012, 6:50:57 AM6/27/12
to django...@googlegroups.com
I've found that this is a fairly common situation. For instance, Location has an FK to Company,
and then ManyToMany to StaffMember. But, only StaffMembers that have their FK set to
the same Company should be selectable in their inline.

This need not just be a ManyToMany thing, either. The Manager of a Location should also
be a StaffMember, but may only be one who is associated with the same Company.

This is one example: another, perhaps more common one, is Country & State/Province.

The available choices for a State/Province depend upon which Country is selected.

For the OP: the only way to do this requires JavaScript on the client end, and creating
views to return the limited set of objects you wish to be able to select from. When your
user changes Country, for instance, you then fetch the available list of States for that
country, and use that to populate the State field options.

I have an example (of exactly this) in my fork of django-countries: 

Specifically, have a look at the JS: 

It's not especially well documented, and the JS only works for country field being 
called country, and province field being called province, but it might be a nice start for you
to see how to do it.


Matt.
Reply all
Reply to author
Forward
0 new messages