Filtering User Data/Records

23 views
Skip to first unread message

tech george

unread,
Apr 7, 2022, 6:09:40 AM4/7/22
to django...@googlegroups.com
Hello,

I am trying to filter my medicine stock data so that Pharmacist 1 can only view their records but not  Pharmacist 's 2 records.

So far nothing is filtered and all the pharmacists can see all the available records, Please advise.

Here is my models;
User Model.PNG

Stocks Model.PNG

Here is my form;

Stocks Model.PNG

Here is my Views:

Views.PNG

Here is the stock records template:

manage_stocks template.PNG

Antonis Christofides

unread,
Apr 7, 2022, 8:06:39 AM4/7/22
to django...@googlegroups.com

Hello,

your code is too large. Please post the shortest code possible that produces the problem. At the very least, please tell us which line of the code is supposed to do the filtering.

Regards,

Antonis

Antonis Christofides
+30-6979924665 (mobile)
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CADYG20HZuvtTJSW61%2BWWg-TSJ5GRmrUM%3DKRqdXtXDMzFUU7GHg%40mail.gmail.com.

Ryan Nowakowski

unread,
Apr 15, 2022, 2:03:46 PM4/15/22
to django...@googlegroups.com
On Thu, Apr 07, 2022 at 01:08:19PM +0300, tech george wrote:
> I am trying to filter my medicine stock data so that Pharmacist 1 can only
> view their records but not Pharmacist 's 2 records.
>
> So far nothing is filtered and all the pharmacists can see all the
> available records, Please advise.

I'm assuming the view you're having problems with is manageStock3. You
probably want to filter stocks based on the pharmacist that is logged in. Try
something like:

stocks = Stock.objects.filter(pharmacist_id=request.user)
Reply all
Reply to author
Forward
0 new messages