Display Many to Many Field in Django admin site

133 views
Skip to first unread message

mansi thakkar

unread,
Apr 3, 2018, 11:22:02 AM4/3/18
to Django users
Hello ,

In my database, there is one table named Product and the other table is Ingredient. Both are related with ManyToMany Relationship using bridge entity (table) named ProductIngredient. 

I am trying to display Many To Many field named ingredient in my Django admin site. 

Here is the attached code and screen shot of the error.

I would like to know the solution of this error and also any other way to display  the list of ingredients for each product. 

Thank you.
get_ingredientsProblem.png
ProductIngredient.png

squal poreover

unread,
Apr 3, 2018, 11:57:38 AM4/3/18
to django...@googlegroups.com
I need to see get_ingredients() . To guess what's happening?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/63c89597-39c0-4765-ab43-4df41e729f4b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

mansi thakkar

unread,
Apr 3, 2018, 12:05:42 PM4/3/18
to Django users
It is there in ProductIngredient.png.

Julio Biason

unread,
Apr 3, 2018, 12:48:34 PM4/3/18
to django...@googlegroups.com
It seems your `get_ingredients()` is expecting the Product itself and another object (for some reason).

Have you tried to remove `obj` from the parameters and use `self` in that function?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.



--
Julio Biason, Sofware Engineer
AZION  |  Deliver. Accelerate. Protect.
Office: +55 51 3083 8101  |  Mobile: +55 51 99907 0554

mansi thakkar

unread,
Apr 3, 2018, 1:15:38 PM4/3/18
to Django users
Yes I have. But it didn't work. Basically my product has many ingredients and on ingredient is contained in many products so all I need is just display product with all the ingredients it contains on admin site.


On Tuesday, April 3, 2018 at 12:48:34 PM UTC-4, Julio Biason wrote:
It seems your `get_ingredients()` is expecting the Product itself and another object (for some reason).

Have you tried to remove `obj` from the parameters and use `self` in that function?
On Tue, Apr 3, 2018 at 12:22 PM, mansi thakkar <mansith...@gmail.com> wrote:
Hello ,

In my database, there is one table named Product and the other table is Ingredient. Both are related with ManyToMany Relationship using bridge entity (table) named ProductIngredient. 

I am trying to display Many To Many field named ingredient in my Django admin site. 

Here is the attached code and screen shot of the error.

I would like to know the solution of this error and also any other way to display  the list of ingredients for each product. 

Thank you.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

Muhammad bin-haneef

unread,
Apr 3, 2018, 5:53:03 PM4/3/18
to django...@googlegroups.com
kindly share the code where you registered your product for admin site and you are calling "get_ ingredients()" method.

As the error shows your method needs 2 arguments to pass when you call "get_ingredients()".

To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

carlos

unread,
Apr 3, 2018, 7:14:03 PM4/3/18
to django...@googlegroups.com
[i.fields for i in self.ingredients.objects.all()]
fields is you method __str__ back, try comments __str__ method in model  Ingredients

or this function get_ingredient create in admin files and used obj parameter

cheers


For more options, visit https://groups.google.com/d/optout.



--
att.
Carlos Rocha
Reply all
Reply to author
Forward
0 new messages