인벤토리 관리를 위해 장고 앱을 사용하고 있습니다. 장고가 아래 URL과 같은 URL을 처리하기를 원합니다.Django 클래스 기반보기 및 일반보기 세부 정보 사용
"foo : 8000/stores/Electrical Store /"여기서 "Electrical Store"는 상점 목록을 표시하는보기에 의해 생성됩니다. http 응답은 ListView 일반 뷰를 사용하여 생성되었습니다. 또한 템플릿 뷰를 사용하여 생성 할 수도 있습니다. 클래스 기반 뷰의 작동 방식을 익히는 동안 여러 가지 방법을 시도했습니다. "저장 정보"내가 얻을 저장소에 제품의 목록을하는 HTTP 페이지를 렌더링하는 장고를 얻을 수하려고 할 때
내 문제는 404 오류 아래 : (? P \ + w)
^저장// $ [name = 'stores_product'] 현재 URL 인 Electrical Store /가 일치하지 않습니다.
그리고 나는 내 코드에서 어디가 잘못되었는지 잘 모르겠다. 기본적으로 문서는 전달하려는 개념을 설명하기에 충분한 정보 나 예제를 제공하지 않는다. 아래에서 관련 모델 및 뷰를 제공했습니다. 제발 도와주세요 ... 그 다음 정규 표현식의 \w
일부 일치하지 않는
# models
# PRODUCT MODEL
class Product(models.Model):
# Desription - ID
name = models.CharField(primary_key = True, unique = True, max_length = 100)
description = models.TextField(max_length = 200)
# Amount per containment unit
amount_per_containment_unit = models.IntegerField("Unit Count", default = 0)
def __unicode__(self):
# return unicode(self.datetime)
return unicode(self.name)
class Meta:
ordering = ["name"]
# STORE MODEL
# A Store has a name, an address, a phone number, a group of users who act as curators and a list of stock
# items.
class Store(models.Model):
name = models.CharField(primary_key = True, max_length = 100)
address = models.CharField(max_length = 100)
phone = models.CharField(max_length = 100)
curators = models.ManyToManyField(User, verbose_name = "Curator", blank = True, null = True)
products = models.ManyToManyField(Product, through = "StoreProduct", blank = True, null = True)
# Curator list
def curator_list(self):
return ",\n".join([obj.first_name for obj in self.curators.all()])
def __unicode__(self):
# return unicode(self.datetime)
return unicode(self.name)
class Meta:
ordering = ["name"]
# StoreProduct MODEL
class StoreProduct(models.Model):
store = models.ForeignKey(Store)
product = models.ForeignKey(Product)
quantity = models.IntegerField(default = 0)
total = models.IntegerField(default = 0)
class Meta:
unique_together = (("store", "product"),)
def __init__(self, *args, **kwargs):
super(StoreProduct, self).__init__(*args, **kwargs)
if self.total == None and self.store and self.product and not self.pk:
self.total = self.product.amount_per_containment_unit * self.quantity
def save(self, *args, **kwargs):
if self.store and self.product and self.quantity:
self.total = self.product.amount_per_containment_unit * self.quantity
super(StoreProduct, self).save(*args, **kwargs)
# views
class StoreList(TemplateView):
# Template
template_name = "inventory/store/store_list.html"
# Context
def get_context_data(self, **kwargs):
context = super(StoreList, self).get_context_data(**kwargs)
context["store_list"] = Store.objects.all()
return context
class StoreProductList(TemplateView):
template_name = "inventory/store/store_products.html"
# Context
def get_context_data(self, **kwargs):
# Objects
self.store_inst = Store.objects.get(pk = self.kwargs["name"])
self.queryset = StoreProduct.objects.filter(store = self.store_inst)
print self.store_inst
context = super(StoreList, self).get_context_data(**kwargs)
# Store primary key
context["store"] = self.store_inst
context["store_products"] = self.queryset