Reputation: 9615
I have model that looks like this:
class Beacon(models.Model):
name = models.CharField()
bid = models.CharField()
campaigns = models.ManyToMany(Campaign)
location = models.ForeignKey(Location)
In my api view, I am trying to find a specific Beacon given a bid (this is beacon id btw). So I have something that looks like this:
def SawBeacon(request, beacon_id):
if request.method == 'GET':
Beacon = Beacon.objects.filter(bid__beacon_id=%s) % beacon_id
This doesn't work.. But I think you get the idea of what I am trying to do. I want to take the incoming beacon_id argument and filter down to a specific beacon that matches this ID.
Upvotes: 1
Views: 73
Reputation: 8539
If you're getting one instance, you'll want to use get rather than filter. Try:
Beacon.objects.get(bid=beacon_id)
When you use filter, you'll return a queryset.
Upvotes: 2