Hi Rishabh,
On Jun 24, 12:19 am, "Rishabh Manocha" <
rmano...@gmail.com> wrote:
> Ok, so I need a bit more direction here. I've got newforms-admin setup and
> working as far as displaying the various FK relationships a user has on
> his/her page. However, I'm still not able to figure out how to display FK
> relationships in the list_filter page. Here is my setup (the UserTechSkill
> from above has not changed, except for the admin stuff):
>
> Note: I haven't copied and pasted here - don't have my work laptop with me
> right now - so there might be some typos, but the logic is the same.
>
> in models.py:
class UserTechSkill(models.Model):
user = models.ForeignKey(User,edit_inline = models.TABULAR)
skill = models.ForeignKey(TechSkillsList,core=True)
prof_level = models.ForeignKey(ProficiencyLevel,core=True)
years = models.IntegerField("Years of Experience", max_length=2)
def __str__(self):
return u'%s' %
';'.join([str(self.skill),str(self.prof_level)])
>
> from django.contrib.auth.admin import UserAdmin
>
> ...
>
> class MyUserAdmin(UserAdmin):
> inlines = [UserTechSkillsAdmin,...]
> list_filter = ('is_staff',)
>
> admin.site.unregister(User)
> admin.site.register(User,MyUserAdmin)
>
> Now what I would like to be able to do is be able to add a TechSkillsList
> filter to the list_filter tuple. I figure that since a user is related to
> the UserTechSkill class and a UserTechSkill class is related to the
> TechSkillsList class, there must be some way I can get a list of
> TechSkillsList in the User class (a list of TechSkillsList which includes
> skills chosen by all users, but not the ones that haven't been selected by
> anyone yet). Can someone point me in the right direction here??
Unfortunately, there's no *easy* way in newforms-admin to filter by a
field that doesn't existly directly in the model in question (the
'User' model in your case.)
It is possible to create a custom FilterSpec but the way that's wired
into the admin ChangeList screen requires the filter to be on a field
that is defined in the model. Since UserTechSkill is not a field in
User, MyUserAdmin can't have a list_filter on it much less on
UserTechSkill.skill.
You could create your own view for a custom change list screen for
your user model. That way, in your own, template you would be able to
display any custom filters you like. Clicking on a change list item
could be linked to the existing admin add/update URL for that user
object.
-Rajesh D