Django parent.child_set no errors but not showing in html

青春壹個敷衍的年華 提交于 2020-08-10 19:35:49

问题


Views.py defining the context in view

def customers(request, pk):
    customer = Customer.objects.get(id=pk)
    
    issues = customer.issue_set.all()
    receives = customer.receive_set.all()
    context={'customer':customer,'issues':issues,'receives':receives}
    return render(request,'accounts/customers.html')

in html

    <div class="col-md">
        <div class="card card-body">
            <h5>Contact Information</h5>
            <hr>
            <p>Email: {{customer.email}}</p>
            <p>Phone: {{customer.phone}}</p>
        </div>
    </div>
{% for issue in issues %}

                <td>{{issue.item}}</td>>
                <td>{{issue.item.category}}</td>
                <td>{{issue.date_created}}</td>
                <td>{{issue.status}}</td>
                <td><a href="">UPDATE</td>
                <td><a href="">DELETE</td>
                {% endfor %}
#Model
class Item(models.Model):
    CATEGORY = (
        ('Gudang Kering', 'Gudang Kering'),
        ('Gudang Basah','Gudang Basah'),
        )
    name = models.CharField(max_length=200,null= True)
    stock = models.IntegerField(default='0', blank=False, null=True)
    category = models.CharField(max_length=200,null= True,choices=CATEGORY)
    reorderlevel = models.IntegerField(default='0', blank=False, null=True)
    maxreorderlevel = models.IntegerField(default='0', blank=False, null=True)
    description = models.CharField(max_length=200,null= True, blank= True)
    date_created = models.DateTimeField(auto_now_add= True)
    tags = models.ManyToManyField(Tag)
    
    def __str__(self):
        return self.name

class Issue(models.Model):
    STATUS = (
        ('Pending', 'Pending'),
        ('Granted','Granted'),
        ('Denied','Denied'),
        )
    customer = models.ForeignKey(Customer, null=True, on_delete= models.SET_NULL)
    item = models.ForeignKey(Item, null=True, on_delete= models.SET_NULL)
    quantity = models.IntegerField(default='0', blank=False, null=True)
    date_created = models.DateTimeField(auto_now_add=True, auto_now=False)
    status = models.CharField(max_length=200,null= True, choices=STATUS)

    def __str__(self):
        return self.status + '  ' +str(self.customer)

I tried to get the object by id of the customer in order to make it a dynamic url where the url will depend on str:pk of customer id i managed to show output data if i do

customer = Customer.objects.all #but that will show all the customer 

so i tried as in the view to get the id and define it with parent.child_set.all but it doesn't show up,even the text update and delete don't show up in

来源:https://stackoverflow.com/questions/63050160/django-parent-child-set-no-errors-but-not-showing-in-html

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!