I want to ask. Can i create multiple view my items in django admin. I have a many to many relationship, so i created an associative entity. But i can't understand how view this in django admin. Can someone help me.
models.py
from django.db import models
from django.contrib import admin
class Client(models.Model):
f_name = models.CharField(verbose_name = "Фамилия", max_length = 100)
l_name = models.CharField(verbose_name = "Имя", max_length = 100)
m_name = models.CharField(verbose_name = "Отчество", max_length = 100)
phone = models.CharField(verbose_name = "Телефон", max_length = 100)
city = models.CharField(verbose_name = "Город", max_length = 100)
address = models.CharField(verbose_name = "Адрес", max_length = 200)
def __str__(self):
return self.f_name + " " + self.l_name + " (" + self.phone + ")"
class Item(models.Model):
name = models.CharField(verbose_name = "Название", max_length = 100)
TYPE_ITEMS = (
("shirt", "Футболка"),
("shoes", "Обувь"),
("bags", "Рюкзаки и сумки"),
("heads", "Головные уборы"),
("others", "Другое"),
)
type_item = models.CharField(verbose_name = "Тип продукта",
choices = TYPE_ITEMS, max_length = 6,
default = "shirt")
other = models.TextField("другая информация")
color = models.CharField("Цвет(а)", max_length = 100)
cost = models.IntegerField("Стоимость за штуку", default = 0)
is_available_now = models.BooleanField("Есть ли в наличии?",
default = False)
available_count = models.IntegerField("Количество в наличии", default = 0)
photo = models.ImageField("Фото", upload_to = "media")
def __str__(self):
return self.name + " " + self.color + " (" + str(self.cost) + " грн)"
class Order(models.Model):
id_client = models.ForeignKey(Client, null = True, blank = True,
verbose_name = "Клиент")
date_order = models.DateField(verbose_name = "Дата заказа")
date_taken = models.DateField(verbose_name = "Дата получения")
is_paid = models.BooleanField(verbose_name = "Оплачено?", default = False)
is_taken = models.BooleanField(verbose_name = "Получил покупатель?",
default = False)
class Order_item(models.Model):
id_order = models.ForeignKey(Order)
id_item = models.ForeignKey(Item)
admin.py
admin.site.register(Item)
admin.site.register(Order)
admin.site.register(Client)
admin.site.register(Order_item)
If user creates order, how can i view what he buy?
If user in admin selects an order i want to view many items. Can i create this with django admin ?
Instead of use
Order_item
class, you should add aitems = models.ManyToManyField(Item)
field into your currentOrder
class.