Reputation: 2656
class BillList(models.Model):
username = models.ForeignKey(User)
billno = models.CharField(max_length=15)
class OrderDetails(models.Model):
billno = models.ForeignKey(BillList)
orderdetails = models.TextField()
User
is the one within django.contrib.auth.models
.
I need to retreive all billno
of a particular user. How do I go about doing this simple query in Django-nonrel on Appengine?
If I do this:
iq = User.objects.filter(username = "name1")
BillList.objects.filter(username = iq)
Then I get an error: DatabaseError: Subqueries are not supported.
If I try this straight away BillList.objects.filter(username = "restaurant1")
, then ValueError: invalid literal for long() with base 10: 'restaurant1'
I'm sure it must be possible to go about doing this simple query! Any workarounds?
Upvotes: 0
Views: 123
Reputation: 11360
The others are correct. But, there may be a fundamental problem here with your understanding of the ForeignKey
. For example:
username = models.ForeignKey(User)
That's not really a "username" at all. It is a user object. More understandable would be something like:
user = models.ForeignKey(User)
The User
object is what has the username
property. So to get a person's username, you would use"
BillList.objects.get(billno = 12345).user.username
Then, your queries become:
iq = User.objects.get(username = "name1")
my_list = BillList.objects.all().filter(user = iq)
Or, more directly:
my_list = iq.billist_set.all()
Upvotes: 2