2016-04-22 40 views
-1

美好的一天。int()與基數10的無效文字:'USA'django

上午有一個叫AddInv

AddInv(models.Model): 
    client = models.ForeignKey(User, null=True) 
    description = models.CharField(max_length = 100) 
    price = models.DecimalField(max_digits=10, decimal_places=2) 
    quantity = models.PositiveIntegerField() 
    sold = models.PositiveIntegerField(default=0) 
    details = models.CharField(max_length = 100) 
    country = models.ForeignKey(Signup, null = True) 

    def __str__(self): 
     return self.country 

爲註冊型號模型是

class Signup(models.Model): 
    user = models.OneToOneField(User) 
    phone_number = models.PositiveIntegerField(null=True) 
    zipcode = models.PositiveIntegerField(null=True) 
    street = models.CharField(max_length = 75, null=True) 
    city = models.CharField(max_length = 75, null=True) 
    state = models.CharField(max_length = 75, null= True) 
    country = models.CharField(max_length = 32, null=True, choices = CATEGORIES) 

    def __str__(self): 
     return self.country 

和意見,由國家

有錯誤
def homepage(request): # Client View 
    context = {} 
    items = get_object_or_404(AddInv, country="USA") 
    print "Items", items 
    return render(request, "selly/homepage.html", {'items': items}) 

上午過濾指向

items = get_object_or_404(AddInv, country="USA") 

代碼有什麼問題

+0

參數'country'必須是'Signup'模型的實例。 –

回答

1

試試這個。只是一個假設

items = get_object_or_404(AddInv, country__country="USA") 
+0

感謝@itzmeoontv爲你的建議 – uche

0

我用

items = AddInv.objects.filter(country__country="USA") 

其工作

相關問題