2012-11-30 1 views
1

내가 Windows에서 파이썬 2.7.2 장고 1.4.1이를 실행하고 있습니다에 표시되지 7.기록은 템플릿

나는 SQLite는 DB에 여러 기록을 가지고 있고 나는 그들이 제네릭 클래스 뷰를 사용하여 표시 얻기 위해 노력하고 있어요 목록보기. 나는 할 수없는 것들을 제거하고 모든 것을 가장 간단한 형식으로 제거했지만 그것이 무엇이 될 수 있는지를 알기 위해 어디로 가야할 지 모르겠습니다.

모델 :

class DMG_New_Inv (models.Model): # DMG's 
def __init__(self, *args, **kwargs): 
    super(DMG_New_Inv, self).__init__(*args, **kwargs) 
    self.objects = None 

model_num = models.ForeignKey(DMG_Models_Default, verbose_name='Model') 
serial_num = models.CharField(max_length=25, verbose_name='Serial Number') 
date_in = models.DateField(auto_now_add=True) #this will set the date to the creation date automaticly 
date_out = models.DateField(blank=True, null=True) # the date is was removed from inventory 
status = models.CharField(max_length=2, verbose_name='Asset Status', choices=DMG_ASSET_STATUS) # see list above 
company = models.CharField(max_length=50, verbose_name='Company', blank=True, null=True) # the company or person who received the product 
notes = models.CharField(max_length=255, verbose_name='Notes', blank=True, null=True) 
pass 
class Meta: 
    verbose_name = 'DMG' 
    verbose_name_plural = 'DMGs' 

보기 :

from django.views.generic import list 
from django.views.generic import ListView 
from django.shortcuts import get_object_or_404 

from inventory.models import DMG_New_Inv 

class dmg_new_status(ListView): 

context_object_name = "dmg_new_status" 
template_name = 'inventory/dmg_inv.html' 

def get_queryset(self): 
    status = get_object_or_404(DMG_New_Inv, status__iexact=self.args[0]) 
    return DMG_New_Inv.objects.filter(status__iexact=status) 

내용 :

{% block content %} 

<div id="content"> 

<table cellspacing="3" cellpadding="3"> 
    <tr align="center"> 
     <th>Model</th><th>Serial Number</th><th>Date In</th><th>Date Out</th><th>Status</th><th>Company</th><th>Notes</th> 
    </tr> 
    {% for dmg in dmg_new_status %} 

    <tr align="center"> 
     <td>{{ dmg.model_num }}</td> 
     <td>{{ dmg.serial_num }}</td> 
     <td>{{ dmg.date_in }}</td> 
     <td>{{ dmg.date_out }}</td> 
     <td>{{ dmg.status }}</td> 
     <td> {{ dmg.company }}</td> 
     <td> {{ dmg.notes }}</td> 
    </tr> 
    {% empty %} 
    No DMG's in this list 
    {% endfor %} 
</table> 

{%의 엔드 블록 %}

URL :

(r'^inventory/dmg/(\w+)/$', dmg_new_status.as_view()), #status page 

빈 옵션을 추가하면 경로 문제가 아니며 테이블 헤더는 표시되지만 레코드는 표시되지 않습니다. 추측해야만하고 추측하는 경우, 아무 것도 반환하지 않으므로 배열이 비어 있습니다. 이 문제를 해결하는 방법을 모르겠습니다. 나는 모든 것을 가져온 콘솔을 열었고 그런 식으로 query_set 함수를 실행했고 아무 것도 얻지 못했습니다. 그래서 나는 그 오류가 거기에 있다고 믿습니다.

감사

답변

1

당신이 get_queryset (자체)에 문제가있는 것 같습니다 ... 첫 번째 줄은 DMG_New_Inv 개체를 얻을 수 있지만 변수 상태에 할당합니다.

(당신은 또한 "상태"가 아닌 다른 변수를 사용 할 수 있습니다)
return DMG_New_Inv.objects.filter(status__iexact=status.status) 

가 ... 같은 마지막 줄이어야한다