Answer the question
In order to leave comments, you need to log in
How to add inline link to user in django admin?
Hello!
I registered the m2m connection with the user in the models:
from django.contrib.auth.models import User
class Item(models.Model):
users = models.ManyToManyField(User, through='Item_in_cart', verbose_name='Заказавшие', related_name='items')
class Item_in_cart(models.Model):
item = models.ForeignKey(Item, verbose_name='Товар', on_delete=models.CASCADE)
user = models.ForeignKey(User, verbose_name='Пользователь', on_delete=models.CASCADE)
amount = models.IntegerField(verbose_name='Количество')
from django.contrib.auth.models import User
class ItemInline(admin.TabularInline):
model = Item_in_cart
extra = 1
class UserAdmin(admin.ModelAdmin):
inlines = (ItemInline, )
admin.site.register(User, UserAdmin)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question