python - Get column data based on foreign key and manytomanyfield in django admin -


i new in django. have following models.

category

id      category_name 1       2       b 

module (category_id foreignkey)

id      module_name    category_id 1       x              1    2       y              2      

category_user (user_id manytomanyfield category_id)

id      category_id    user_id 1       1              23  2       2              23    

so want display data x & y module in admin category edit page if category id 1 & 2 assigned user 23.

admin.py

class categoryadmin(admin.modeladmin):     list_display = ('category_name','category_desc')     filter_horizontal = ('user',)     readonly_fields = ('allowed_module_names',)      def allowed_module_names(self, instance):         modules = []         module_names = instance.category.values_list("module_name")         print(module_names) 

the query returns blank.

any highly appreciated. in advance.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -