Enzo Massaki
Enzo Massaki

Reputation: 311

Making a GET request with filter

My model is the following

class PokerRoom(models.Model):
STATUS = (("Pending", "Pending"), ("Finished", "Finished"))

status = models.CharField(
    max_length=11,
    choices=STATUS,
    verbose_name=_("Status da Story"),
    default="Pending",
)
name = models.CharField(max_length=200, verbose_name=_("room name"), validators=[alphanumeric])
slug = models.CharField(max_length=200, verbose_name=_("room slug"), null=True, blank=True)
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
styleCards = MultiSelectField(choices=CHOICES, default=FIBONACCI)
datetime = models.DateTimeField(null=True, blank=True)
date = models.CharField(max_length=10, null=True, blank=True)
user = models.ForeignKey(User, on_delete=DO_NOTHING)
first_name_user = models.CharField(
    max_length=200, verbose_name=_("user name"), null=True, blank=True
)
deck = models.ForeignKey(Pack, on_delete=models.CASCADE)
index = models.IntegerField(
    null=True, blank=True, verbose_name=_("story being voted")
)

I'm my application, I want to make a searchbar for "status" and "name" and do a GET request with those filter that would be provided by the client when he make the search. But I don't know how to do that in my views.py

I was thiking in a GET method like this, but I don't know how to get the planningName and planningStatus from the frontend.

    def get(self, request, pk):
    """GET of PokerRoom historic"""
    user = request.user
    pk = self.kwargs["pk"]
    planningName = 
    planningStatus = 
    moderatorRoom = PokerRoom.objects.values("id", "first_name_user", "date", "name", "status", "styleCards", "datetime", 'slug'
    ).filter(Q(user= user) | Q(name=planningName) | Q(status=planningStatus)).order_by("-datetime")

Can someone helpe me?

Upvotes: 2

Views: 568

Answers (1)

Aby Sebastian
Aby Sebastian

Reputation: 62

Suppose the name of the input field is planningName, you can get the value in views.py by using

planningName = request.GET.get('planningName')
planningStatus = request.GET.get('planningStatus')

Upvotes: 2

Related Questions