NameError:

2022-04-08 Thread tech george
Hello,

I've been struggling with the below error, what might be the problem?

I have used the same ForeignKey in other models.. all works ok, except this.

Please advise.

*Models:*

class CustomUser(AbstractUser):
user_type_data = ((1, "AdminHOD"), (2, "Pharmacist"), (3, "Doctor"),
(4, "PharmacyClerk"),(5, "Patients"))
user_type = models.CharField(default=1, choices=user_type_data,
max_length=10)



class Patients(models.Model):
gender_category=(
('Male','Male'),
('Female','Female'),
)

nurse = models.ForeignKey(Pharmacist, related_name='Pharmacist',
on_delete=models.CASCADE, null=True)
admin = models.OneToOneField(CustomUser,null=True, on_delete =
models.CASCADE)
reg_no=models.CharField(max_length=30,null=True,blank=True,unique=True)

gender=models.CharField(max_length=7,null=True,blank=True,choices=gender_category)
first_name=models.CharField(max_length=20,null=True,blank=True)
last_name=models.CharField(max_length=20,null=True,blank=True)
date_admitted=models.DateTimeField(auto_now_add=True, auto_now=False)
last_updated = models.DateTimeField(auto_now_add=False, auto_now=True)

def __str__(self):
return str(self.admin)


*Error:*

nurse = models.ForeignKey(Pharmacist, related_name='Pharmacist',
on_delete=models.CASCADE, null=True)
NameError: name 'Pharmacist' is not defined


Regards,

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADYG20GbMnoGjkT7VtD1FFMw3Tr8Axaepnf27vDyvqYvMb%2BUiQ%40mail.gmail.com.


Re: NameError:

2022-04-09 Thread tech george
Hello Antonis,

Thanks, it worked.

Much appreciated.

Regards,

On Fri, Apr 8, 2022 at 11:10 PM Antonis Christofides <
anto...@antonischristofides.com> wrote:

> Hi! In the line where the error occurs, Pharmacist has not been defined
> yet. Move your Pharmacist model before your Patients model.
>
> Regards,
>
> Antonis
>
> On 08/04/2022 20.49, tech george wrote:
>
> Hello,
>
> I've been struggling with the below error, what might be the problem?
>
> I have used the same ForeignKey in other models.. all works ok, except
> this.
>
> Please advise.
>
> *Models:*
>
> class CustomUser(AbstractUser):
> user_type_data = ((1, "AdminHOD"), (2, "Pharmacist"), (3, "Doctor"),
> (4, "PharmacyClerk"),(5, "Patients"))
> user_type = models.CharField(default=1, choices=user_type_data,
> max_length=10)
>
>
>
> class Patients(models.Model):
> gender_category=(
> ('Male','Male'),
> ('Female','Female'),
> )
>
> nurse = models.ForeignKey(Pharmacist, related_name='Pharmacist',
> on_delete=models.CASCADE, null=True)
> admin = models.OneToOneField(CustomUser,null=True, on_delete =
> models.CASCADE)
> reg_no=models.CharField(max_length=30,null=True,blank=True,unique=True)
>
> gender=models.CharField(max_length=7,null=True,blank=True,choices=gender_category)
> first_name=models.CharField(max_length=20,null=True,blank=True)
> last_name=models.CharField(max_length=20,null=True,blank=True)
> date_admitted=models.DateTimeField(auto_now_add=True, auto_now=False)
> last_updated = models.DateTimeField(auto_now_add=False, auto_now=True)
>
> def __str__(self):
> return str(self.admin)
>
>
> *Error:*
>
> nurse = models.ForeignKey(Pharmacist, related_name='Pharmacist',
> on_delete=models.CASCADE, null=True)
> NameError: name 'Pharmacist' is not defined
>
>
> Regards,
>
>
>
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CADYG20GbMnoGjkT7VtD1FFMw3Tr8Axaepnf27vDyvqYvMb%2BUiQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CADYG20GbMnoGjkT7VtD1FFMw3Tr8Axaepnf27vDyvqYvMb%2BUiQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/6f64f27c-ec8c-da80-5878-5520c7017b35%40antonischristofides.com
> <https://groups.google.com/d/msgid/django-users/6f64f27c-ec8c-da80-5878-5520c7017b35%40antonischristofides.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADYG20HOOnQksvprL5VgiR1pxCaqaujdFmuHO4LK-nNQfGiprQ%40mail.gmail.com.


Calculated Fields

2022-04-10 Thread tech george
Hello,

I am trying to calculate fields directly from a model but no luck. I want
to get total_price from quantity, reoder_level and unit price. My code is
abelow, Please advise.

class Stock(models.Model):
unit_price = models.DecimalField(max_digits=10, decimal_places=2,
default='0', blank=True, null=True)
quantity = models.IntegerField(default='0', blank=True, null=True)
total_price = models.DecimalField(max_digits=10,
decimal_places=2,default=1)
reorder_level = models.IntegerField(default='0', blank=True, null=True)


def save(self, *args, **kwargs):
self.total_price = self.quantity + self.reorder_level *
self.unit_price
super(Stock, self).save(*args, **kwargs)


What am i my doing wrong

Regards,

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADYG20HBcMMGq6QodO0v%2BeZVmfS%2Bmr4aCSro5FZeeRLFdQztnQ%40mail.gmail.com.


Re: Calculated Fields

2022-04-10 Thread tech george
Hello Mike,

Unfortunately it's not calculating the fields as I wanted, instead it's
calculating as below;

reorder_level * unit_price + quantity

Which is wrong because I'm getting less amount.

Regards

On Mon, 11 Apr 2022, 01:56 Mike Dewhirst,  wrote:

>
>
>
>
> --
> (Unsigned mail from my phone)
>
>
>
> ---- Original message 
> From: tech george 
> Date: 11/4/22 03:50 (GMT+10:00)
> To: django-users@googlegroups.com
> Subject: Calculated Fields
>
> Hello,
>
> I am trying to calculate fields directly from a model but no luck. I want
> to get total_price from quantity, reoder_level and unit price. My code is
> abelow, Please advise.
>
> class Stock(models.Model):
> unit_price = models.DecimalField(max_digits=10, decimal_places=2,
> default='0', blank=True, null=True)
> quantity = models.IntegerField(default='0', blank=True, null=True)
> total_price = models.DecimalField(max_digits=10,
> decimal_places=2,default=1)
> reorder_level = models.IntegerField(default='0', blank=True, null=True)
>
>
> def save(self, *args, **kwargs):
> self.total_price = self.quantity + self.reorder_level *
> self.unit_price
> super(Stock, self).save(*args, **kwargs)
>
>
> What am i my doing wrong
>
> If it was my code, I would extract the calculation into a model method and
> call it from the save method as you are doing.
>
> That would make it easier to unit-test and perhaps discover that there
> should be parens around the addition.
>
> You also need to call save on your model to execute the code.
>
> Apart from that, at first glance your code should work.
>
>
>
> Regards,
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CADYG20HBcMMGq6QodO0v%2BeZVmfS%2Bmr4aCSro5FZeeRLFdQztnQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CADYG20HBcMMGq6QodO0v%2BeZVmfS%2Bmr4aCSro5FZeeRLFdQztnQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/6253606d.1c69fb81.ac7f2.09bcSMTPIN_ADDED_MISSING%40gmr-mx.google.com
> <https://groups.google.com/d/msgid/django-users/6253606d.1c69fb81.ac7f2.09bcSMTPIN_ADDED_MISSING%40gmr-mx.google.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADYG20Ec5fq2WJLsuTiaCLycc%2B%2B%3DM7iscYVf1PbvfyDEqhtPow%40mail.gmail.com.


Re: Calculated Fields

2022-04-11 Thread tech george
Hello Antonis,

Thanks for the advice and the solution,

That solved my issue.

Thanks again.

On Mon, Apr 11, 2022 at 9:04 AM Antonis Christofides <
anto...@antonischristofides.com> wrote:

> As was found out with the conversation with Mike Dewhirst, the error
> appears to be because of wrong understanding of operator precedence
> <https://docs.python.org/3/reference/expressions.html#operator-precedence>.
> That's easy to correct with parentheses.
>
> Except for that, I wouldn't do it that way; I wouldn't store the total
> price in the database, because it's likely to create problems. Models that
> have not (yet) been saved to the database will not have a total price.
> Models that have been loaded from the database, modified, but not (yet)
> updated in the database will have a wrong total price. Saving to the
> database with bulk operations or with plain SQL may result in no total
> price. These are all symptoms of storing redundant information in the
> database, which is something that should be avoided.
>
> Instead, I would do this:
> class Stock(models.Model):
> unit_price = models.DecimalField(max_digits=10, decimal_places=2,
> default='0', blank=True, null=True)
> quantity = models.IntegerField(default='0', blank=True, null=True)
> reorder_level = models.IntegerField(default='0', blank=True, null=True)
>
> @property
>     def total_price(self):
> return (self.quantity + self.reorder_level) * self.unit_price
>
>
>
> On 10/04/2022 20.49, tech george wrote:
>
> Hello,
>
> I am trying to calculate fields directly from a model but no luck. I want
> to get total_price from quantity, reoder_level and unit price. My code is
> abelow, Please advise.
>
> class Stock(models.Model):
> unit_price = models.DecimalField(max_digits=10, decimal_places=2,
> default='0', blank=True, null=True)
> quantity = models.IntegerField(default='0', blank=True, null=True)
> total_price = models.DecimalField(max_digits=10,
> decimal_places=2,default=1)
> reorder_level = models.IntegerField(default='0', blank=True, null=True)
>
>
> def save(self, *args, **kwargs):
> self.total_price = self.quantity + self.reorder_level *
> self.unit_price
> super(Stock, self).save(*args, **kwargs)
>
>
> What am i my doing wrong
>
> Regards,
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CADYG20HBcMMGq6QodO0v%2BeZVmfS%2Bmr4aCSro5FZeeRLFdQztnQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CADYG20HBcMMGq6QodO0v%2BeZVmfS%2Bmr4aCSro5FZeeRLFdQztnQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8efea23c-52d8-6ac1-b94e-3cb9ad46d086%40antonischristofides.com
> <https://groups.google.com/d/msgid/django-users/8efea23c-52d8-6ac1-b94e-3cb9ad46d086%40antonischristofides.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADYG20FeUPLkT6wYn6%3DHvMDa8u9d62i4HEo6Zy410Xjyz%2B9%2Bdw%40mail.gmail.com.


Calculations Between Models

2022-04-19 Thread tech george
Hello,

I have a model Staff and LeaveReportStaff, I wanted to get leave_balance
between Total_Leave_Days and leave_days.

Please advise the best way forward.

class Staff(models.Model):
Total_Leave_Days = models.PositiveIntegerField(default=0)
course = models.ForeignKey(Course, on_delete=models.DO_NOTHING,
null=True, blank=False)
admin = models.OneToOneField(CustomUser, on_delete=models.CASCADE)

class LeaveReportStaff(models.Model):
staff = models.ForeignKey(Staff, on_delete=models.CASCADE)
start_date = models.DateField()
end_date = models.DateField()
leave_type = models.CharField(choices=LEAVE_TYPE, max_length=25,
null=True, blank=False)

@property
def leave_days(self):
return (self.end_date - self.start_date).days

@property
def leave_balance(self):
return (self.Total_Leave_Days - self.leave_days)

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADYG20F5wx1P7uWzswKue0vojoVMLZewVdEbcFKFO0Chn2%3Dubg%40mail.gmail.com.


Fetching Data Between Models

2022-04-20 Thread tech george
I have a model Staff and LeaveReportStaff, I wanted to get leave_balance
between Total_Leave_Days and leave_days. I already used Foreignkey for
staff but I'm not sure if it is right to use Foreignkey again.

Please advise the best way forward.

class Staff(models.Model):
Total_Leave_Days = models.PositiveIntegerField(default=0)
course = models.ForeignKey(Course, on_delete=models.DO_NOTHING,
null=True, blank=False)
admin = models.OneToOneField(CustomUser, on_delete=models.CASCADE)


class LeaveReportStaff(models.Model):
staff = models.ForeignKey(Staff, on_delete=models.CASCADE)
start_date = models.DateField()
end_date = models.DateField()
leave_type = models.CharField(choices=LEAVE_TYPE, max_length=25,
null=True, blank=False)

@property
def leave_days(self):
return (self.end_date - self.start_date).days

@property
def leave_balance(self):
return (self.Total_Leave_Days - self.leave_days)

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADYG20F2ySFndjkc6o3oPH%3DxjPc450hXuGRM5c7_cnBMOy9ZiQ%40mail.gmail.com.


Models Culculations

2022-08-03 Thread tech george
Hello,

Please help with the below, I am trying to get dispense_quantity from
Dispense Model and subtract it from the quantity on Stock Model.

Then after that get something like this;

@property
def closing_stock(self):
  return (self.quantity - self. quantity_issued  )

class Stock(models.Model):
unit_price = models.DecimalField(max_digits=10, decimal_places=2,
default='0', blank=True, null=True)
quantity = models.IntegerField(default='0', blank=True, null=True)
total_price = models.DecimalField(max_digits=10, decimal_places=2,
default=1)
total_stock = models.IntegerField(default='0', blank=True, null=True)
receive_quantity = models.IntegerField(default='0', blank=True, null=True)
reorder_level = models.IntegerField(default='0', blank=True, null=True)
reorder_price = models.DecimalField(max_digits=10,
decimal_places=2, default='0', blank=True, null=True)

def __str__(self):
return str(self.drug_name)

@property
def total_price(self):
return (self.quantity + self.reorder_level) * self.unit_price

@property
def total_stock(self):
return (self.quantity + self.reorder_level)

@property
def reorder_stock(self):
return (self.reorder_level * self.reorder_price)

class Dispense(models.Model):
nurse = models.ForeignKey(Pharmacist, on_delete=models.CASCADE, null=True)
patient_id = models.ForeignKey(Patients,
on_delete=models.DO_NOTHING, null=True)
drug_id = models.ForeignKey(Stock, on_delete=models.SET_NULL,
null=True, blank=False)
dispense_quantity = models.PositiveIntegerField(default='1',
blank=False, null=True)
taken = models.CharField(max_length=300, null=True, blank=True)

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADYG20E1AotncUkEVrooR4RqHr24gPK_oCd8S4iqre2HOfdABg%40mail.gmail.com.


Negative Stock Prevention

2022-08-29 Thread tech george
Hello,

Please help crack the below code, I want to prevent negative stock, and if
the stock is == 0, deduct it from reorder_level instead.
Currently, the stock goes negative.

models.py

class Stock(models.Model):
quantity = models.IntegerField(default='0', blank=True, null=True)
reorder_level = models.IntegerField(default='0', blank=True, null=True)

class Dispense(models.Model):
drug_id = models.ForeignKey(Stock,
on_delete=models.SET_NULL,null=True,blank=False)
dispense_quantity = models.PositiveIntegerField(default='1',
blank=False, null=True)
taken=models.CharField(max_length=300,null=True, blank=True)

views.py

try:

if request.method == 'POST':
if form.is_valid():
username = form.cleaned_data['taken']
qu=form.cleaned_data['dispense_quantity']
ka=form.cleaned_data['drug_id']
# print(username)



stock= eo=Stock.objects.annotate(
expired=ExpressionWrapper(Q(valid_to__lt=Now()),
output_field=BooleanField())
).filter(expired=False).get(id=username)
form=DispenseForm(request.POST or None, instance=stock)
instance=form.save()
# print(instance)
if quantity > 0
instance.quantity-=qu
instance.save()
else:
instance.reorder_level-=qu
instanc.save()

form=DispenseForm(request.POST or None
,initial={'patient_id':queryset})
form.save()

messages.success(request, "Drug Has been Successfully Dispensed")

return redirect('manage_patient_pharmacist')
else:
messages.error(request, "Validity Error")

return redirect('manage_patient_pharmacist')

context={
"patients":queryset,
"form":form,
# "stocks":stock,
"drugs":drugs,
"prescrips":prescrips,
"expired":ex,
"expa":eo,

}
if request.method == 'POST':

print(drugs)
context={
"drugs":drugs,
form:form,
"prescrips":prescrips,
"patients":queryset,
"expired":ex,
"expa":eo,

}
except:
messages.error(request, "Dispensing Not Allowed! The Drug is
Expired ,please do a re-stock ")
return redirect('manage_patient_pharmacist')
context={
"patients":queryset,
"form":form,
# "stocks":stock,
"drugs":drugs,
"prescrips":prescrips,
"expired":ex,
"expa":eo,

}

return render(request,'templates/discharge.html',context)

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADYG20GtQH-g%2Br2-T7VaD3xna-jtydr%3DsH6RSQnBJfBza39caw%40mail.gmail.com.


Re: Negative Stock Prevention

2022-08-31 Thread tech george
Hello,

Sorry for the late reply.

I changed the models as below and added checkConstraint , But when I
migrate I get the below error.

What am I still doing wrong?

class Stock(models.Model):
quantity = models.PositiveIntegerField(default='0', blank=True,
null=True)
reorder_level = models.PositiveIntegerField(default='0', blank=True,
null=True)

class Meta:
CheckConstraint(check=Q(quantity__gt=0), name='quantity')



On Tue, Aug 30, 2022 at 6:09 PM Thomas Couch  wrote:

> I don't see where you define the quantity variable, should that be
> instance.quantity? Also, presumably you want to check if quantity is
> greater than or equal to qu rather than 0.
> Try changing `if quantity > 0` to `if instance.quantity >= qu`
>
>
> On Tuesday, August 30, 2022 at 3:44:51 PM UTC+1 Ryan Nowakowski wrote:
>
>> On Mon, Aug 29, 2022 at 05:18:39PM +0300, tech george wrote:
>> > Please help crack the below code, I want to prevent negative stock, and
>> if
>> > the stock is == 0, deduct it from reorder_level instead.
>> > Currently, the stock goes negative.
>> >
>> > models.py
>> >
>> > class Stock(models.Model):
>> > quantity = models.IntegerField(default='0', blank=True, null=True)
>> > reorder_level = models.IntegerField(default='0', blank=True, null=True)
>> >
>> > class Dispense(models.Model):
>> > drug_id = models.ForeignKey(Stock,
>> > on_delete=models.SET_NULL,null=True,blank=False)
>> > dispense_quantity = models.PositiveIntegerField(default='1',
>> > blank=False, null=True)
>> > taken=models.CharField(max_length=300,null=True, blank=True)
>>
>> Maybe change quantity and reorder_level to PositiveIntegerField?
>>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/9ef2d260-7c1a-4ff1-95ca-c13ded5f9f7bn%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/9ef2d260-7c1a-4ff1-95ca-c13ded5f9f7bn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADYG20F0occUAajR%3DSseRtiW%2Bzjh4THmgN6FEFbFsGcpsmMLZg%40mail.gmail.com.


Re: Negative Stock Prevention

2022-08-31 Thread tech george
Hello,

Sorry the error is:

django.db.utils.IntegrityError: CHECK constraint failed: quantity



On Thu, Sep 1, 2022 at 3:45 AM Ryan Nowakowski  wrote:

> I don't see any error. Did you forget to post it?
>
> On August 31, 2022 5:57:32 AM CDT, tech george 
> wrote:
>>
>> Hello,
>>
>> Sorry for the late reply.
>>
>> I changed the models as below and added checkConstraint , But when I
>> migrate I get the below error.
>>
>> What am I still doing wrong?
>>
>> class Stock(models.Model):
>> quantity = models.PositiveIntegerField(default='0', blank=True,
>> null=True)
>> reorder_level = models.PositiveIntegerField(default='0', blank=True,
>> null=True)
>>
>> class Meta:
>> CheckConstraint(check=Q(quantity__gt=0), name='quantity')
>>
>>
>>
>> On Tue, Aug 30, 2022 at 6:09 PM Thomas Couch  wrote:
>>
>>> I don't see where you define the quantity variable, should that be
>>> instance.quantity? Also, presumably you want to check if quantity is
>>> greater than or equal to qu rather than 0.
>>> Try changing `if quantity > 0` to `if instance.quantity >= qu`
>>>
>>>
>>> On Tuesday, August 30, 2022 at 3:44:51 PM UTC+1 Ryan Nowakowski wrote:
>>>
>>>> On Mon, Aug 29, 2022 at 05:18:39PM +0300, tech george wrote:
>>>> > Please help crack the below code, I want to prevent negative stock,
>>>> and if
>>>> > the stock is == 0, deduct it from reorder_level instead.
>>>> > Currently, the stock goes negative.
>>>> >
>>>> > models.py
>>>> >
>>>> > class Stock(models.Model):
>>>> > quantity = models.IntegerField(default='0', blank=True, null=True)
>>>> > reorder_level = models.IntegerField(default='0', blank=True,
>>>> null=True)
>>>> >
>>>> > class Dispense(models.Model):
>>>> > drug_id = models.ForeignKey(Stock,
>>>> > on_delete=models.SET_NULL,null=True,blank=False)
>>>> > dispense_quantity = models.PositiveIntegerField(default='1',
>>>> > blank=False, null=True)
>>>> > taken=models.CharField(max_length=300,null=True, blank=True)
>>>>
>>>> Maybe change quantity and reorder_level to PositiveIntegerField?
>>>>
>>> --
>>> 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+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/9ef2d260-7c1a-4ff1-95ca-c13ded5f9f7bn%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/9ef2d260-7c1a-4ff1-95ca-c13ded5f9f7bn%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/DDF83E16-47C4-4E38-90DE-6CDAE28268DB%40fattuba.com
> <https://groups.google.com/d/msgid/django-users/DDF83E16-47C4-4E38-90DE-6CDAE28268DB%40fattuba.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADYG20H6Yv_Y0vkgqVzOU90emRP%3DnvUw7vRrM--HGNbb0zZCAA%40mail.gmail.com.


Re: Negative Stock Prevention

2022-08-31 Thread tech george
I managed to remove the error,

I had a negative stock in my DB.

Thanks a lot for the help.

On that note, I was also trying to get the dispensed from stock

I was trying to do this but I don't think it can work since there is
already a foreign key at Dispense model fetching drug_id from stock.

What's the best way out?

@property
def dispensed(self):
return (self.quantity - self.dispense.quantity)




On Thu, Sep 1, 2022 at 6:09 AM Ammar Mohammed  wrote:

> I don't think you need that constraint after using the
> PositiveIntegerField .
>
>
> On Thu, 1 Sep 2022, 02:45 Ryan Nowakowski,  wrote:
>
>> I don't see any error. Did you forget to post it?
>>
>> On August 31, 2022 5:57:32 AM CDT, tech george 
>> wrote:
>>>
>>> Hello,
>>>
>>> Sorry for the late reply.
>>>
>>> I changed the models as below and added checkConstraint , But when I
>>> migrate I get the below error.
>>>
>>> What am I still doing wrong?
>>>
>>> class Stock(models.Model):
>>> quantity = models.PositiveIntegerField(default='0', blank=True,
>>> null=True)
>>> reorder_level = models.PositiveIntegerField(default='0', blank=True,
>>> null=True)
>>>
>>> class Meta:
>>> CheckConstraint(check=Q(quantity__gt=0), name='quantity')
>>>
>>>
>>>
>>> On Tue, Aug 30, 2022 at 6:09 PM Thomas Couch  wrote:
>>>
>>>> I don't see where you define the quantity variable, should that be
>>>> instance.quantity? Also, presumably you want to check if quantity is
>>>> greater than or equal to qu rather than 0.
>>>> Try changing `if quantity > 0` to `if instance.quantity >= qu`
>>>>
>>>>
>>>> On Tuesday, August 30, 2022 at 3:44:51 PM UTC+1 Ryan Nowakowski wrote:
>>>>
>>>>> On Mon, Aug 29, 2022 at 05:18:39PM +0300, tech george wrote:
>>>>> > Please help crack the below code, I want to prevent negative stock,
>>>>> and if
>>>>> > the stock is == 0, deduct it from reorder_level instead.
>>>>> > Currently, the stock goes negative.
>>>>> >
>>>>> > models.py
>>>>> >
>>>>> > class Stock(models.Model):
>>>>> > quantity = models.IntegerField(default='0', blank=True, null=True)
>>>>> > reorder_level = models.IntegerField(default='0', blank=True,
>>>>> null=True)
>>>>> >
>>>>> > class Dispense(models.Model):
>>>>> > drug_id = models.ForeignKey(Stock,
>>>>> > on_delete=models.SET_NULL,null=True,blank=False)
>>>>> > dispense_quantity = models.PositiveIntegerField(default='1',
>>>>> > blank=False, null=True)
>>>>> > taken=models.CharField(max_length=300,null=True, blank=True)
>>>>>
>>>>> Maybe change quantity and reorder_level to PositiveIntegerField?
>>>>>
>>>> --
>>>> 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+unsubscr...@googlegroups.com.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/django-users/9ef2d260-7c1a-4ff1-95ca-c13ded5f9f7bn%40googlegroups.com
>>>> <https://groups.google.com/d/msgid/django-users/9ef2d260-7c1a-4ff1-95ca-c13ded5f9f7bn%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>> --
>> 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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/DDF83E16-47C4-4E38-90DE-6CDAE28268DB%40fattuba.com
>> <https://groups.google.com/d/msgid/django-users/DDF83E16-47C4-4E38-90DE-6CDAE28268DB%40fattuba.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAHs1H7uN4xCF%2B7AKqxSufatWiUN_n9cw4uBALo-ENFOfirp_hg%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAHs1H7uN4xCF%2B7AKqxSufatWiUN_n9cw4uBALo-ENFOfirp_hg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADYG20EXeqBXyAQsG0zpk6HXxcKixhjvy_R9z1QiY6%3Da5cAvFg%40mail.gmail.com.


Filter by date range

2022-09-09 Thread tech george
Hello friends!

I am trying to give users an easier way to filter data by date range.

My views.py code is as below, but unfortunately, it is hiding data without
applying the filter whenever I try to use if, else statements.

Please advise what I might be doing wrong.

views.py

ef referralsReports(request):
if request.method=="POST":
fromdate = request.POST.get('fromdate')
todate = request.POST.get('todate')
searchresults = Prescription.objects.raw('select
id,description,prescribe,ailment,ailment_2,ailment_3,'

'sickOff,referral,date_precribed,nurse_id,patient_id_id,'

'non_work_related_sickOff from pharmacy_prescription where
date_precribed '
 'between
"'+str(fromdate)+'" and "'+str(todate)+'"')
return render(request,
'pharmacist_templates/reports/referrals_report.html', {"data":
searchresults})

else:
displaydata =
Prescription.objects.filter(nurse=request.user.pharmacist).order_by('-id')
return render(request,
'pharmacist_templates/reports/referrals_report.html',
{"data":displaydata})


template

[image: image.png]

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADYG20Go5PXJRP-MGJ07M36ftSaQ6WJVjYg_p4UYB9UUWge-LA%40mail.gmail.com.


Re: Filter by date range

2022-09-09 Thread tech george
Hello Carlos,

I have used the code below as you advised by when I filter the table comes
blank:

query_results = Prescription.objects.filter(date__range=[fromdate,todate])

Regards,


On Fri, Sep 9, 2022 at 6:11 PM carlos  wrote:

> Hello why use raw?
> query_results = Prescription.objects.filter(date__range=[fromdate,todate])
> if you have any problem with performance hit database use select_related
> or used m2m field use prefect_related
> https://docs.djangoproject.com/en/4.1/ref/models/querysets/
>
> best!
>
> On Fri, Sep 9, 2022 at 7:48 AM tech george  wrote:
>
>> Hello friends!
>>
>> I am trying to give users an easier way to filter data by date range.
>>
>> My views.py code is as below, but unfortunately, it is hiding data
>> without applying the filter whenever I try to use if, else statements.
>>
>> Please advise what I might be doing wrong.
>>
>> views.py
>>
>> ef referralsReports(request):
>> if request.method=="POST":
>> fromdate = request.POST.get('fromdate')
>> todate = request.POST.get('todate')
>> searchresults = Prescription.objects.raw('select 
>> id,description,prescribe,ailment,ailment_2,ailment_3,'
>>  
>> 'sickOff,referral,date_precribed,nurse_id,patient_id_id,'
>>  'non_work_related_sickOff 
>> from pharmacy_prescription where date_precribed '
>>  'between 
>> "'+str(fromdate)+'" and "'+str(todate)+'"')
>> return render(request, 
>> 'pharmacist_templates/reports/referrals_report.html', {"data": 
>> searchresults})
>>
>> else:
>> displaydata = 
>> Prescription.objects.filter(nurse=request.user.pharmacist).order_by('-id')
>> return render(request, 
>> 'pharmacist_templates/reports/referrals_report.html', {"data":displaydata})
>>
>>
>> template
>>
>> [image: image.png]
>>
>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CADYG20Go5PXJRP-MGJ07M36ftSaQ6WJVjYg_p4UYB9UUWge-LA%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CADYG20Go5PXJRP-MGJ07M36ftSaQ6WJVjYg_p4UYB9UUWge-LA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> --
> att.
> Carlos Rocha
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAM-7rO3UTB%2Bm7gYzfQ_RB%2BDnDWetnO3E18knFuLPJAU%2BBQrbLw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAM-7rO3UTB%2Bm7gYzfQ_RB%2BDnDWetnO3E18knFuLPJAU%2BBQrbLw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADYG20F%3D3470-FCgJZ0amOHUDV%3DXvHQ6ZWKak2VjcB%2BjD26Qkg%40mail.gmail.com.


Re: Filter by date range

2022-09-10 Thread tech george
Hello Muhammad,

I'm choosing dates between 2022-07-01 and 2022-07-30 which have records in
the db.

I hope i have answered you right.


On Sat, Sep 10, 2022 at 8:41 AM Muhammad Juwaini Abdul Rahman <
juwa...@gmail.com> wrote:

> What's your value of 'fromdate' and 'todate'?
>
> On Sat, 10 Sept 2022 at 13:27, tech george  wrote:
>
>> Hello Carlos,
>>
>> I have used the code below as you advised by when I filter the table
>> comes blank:
>>
>> query_results = Prescription.objects.filter(date__rang
>> e=[fromdate,todate])
>>
>> Regards,
>>
>>
>> On Fri, Sep 9, 2022 at 6:11 PM carlos  wrote:
>>
>>> Hello why use raw?
>>> query_results = Prescription.objects.filter(date__rang
>>> e=[fromdate,todate])
>>> if you have any problem with performance hit database use select_related
>>> or used m2m field use prefect_related
>>> https://docs.djangoproject.com/en/4.1/ref/models/querysets/
>>>
>>> best!
>>>
>>> On Fri, Sep 9, 2022 at 7:48 AM tech george 
>>> wrote:
>>>
>>>> Hello friends!
>>>>
>>>> I am trying to give users an easier way to filter data by date range.
>>>>
>>>> My views.py code is as below, but unfortunately, it is hiding data
>>>> without applying the filter whenever I try to use if, else statements.
>>>>
>>>> Please advise what I might be doing wrong.
>>>>
>>>> views.py
>>>>
>>>> ef referralsReports(request):
>>>> if request.method=="POST":
>>>> fromdate = request.POST.get('fromdate')
>>>> todate = request.POST.get('todate')
>>>> searchresults = Prescription.objects.raw('select 
>>>> id,description,prescribe,ailment,ailment_2,ailment_3,'
>>>>  
>>>> 'sickOff,referral,date_precribed,nurse_id,patient_id_id,'
>>>>  'non_work_related_sickOff 
>>>> from pharmacy_prescription where date_precribed '
>>>>  'between 
>>>> "'+str(fromdate)+'" and "'+str(todate)+'"')
>>>> return render(request, 
>>>> 'pharmacist_templates/reports/referrals_report.html', {"data": 
>>>> searchresults})
>>>>
>>>> else:
>>>> displaydata = 
>>>> Prescription.objects.filter(nurse=request.user.pharmacist).order_by('-id')
>>>> return render(request, 
>>>> 'pharmacist_templates/reports/referrals_report.html', {"data":displaydata})
>>>>
>>>>
>>>> template
>>>>
>>>> [image: image.png]
>>>>
>>>>
>>>> --
>>>> 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+unsubscr...@googlegroups.com.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/django-users/CADYG20Go5PXJRP-MGJ07M36ftSaQ6WJVjYg_p4UYB9UUWge-LA%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/django-users/CADYG20Go5PXJRP-MGJ07M36ftSaQ6WJVjYg_p4UYB9UUWge-LA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>
>>>
>>> --
>>> att.
>>> Carlos Rocha
>>>
>>> --
>>> 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+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAM-7rO3UTB%2Bm7gYzfQ_RB%2BDnDWetnO3E18knFuLPJAU%2BBQrbLw%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CAM-7rO3UTB%2Bm7gYzfQ_RB%2BDnDWetnO3E18knFuLPJAU%2BBQrbLw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
>> 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

Re: Filter by date range

2022-09-11 Thread tech george
Hello,

I have tried debugging as below and it returned data;

search_results =
Prescription.objects.filter(date_prescribed__range=["2022-07-01",2022-07-30"])

Is there another way i can filter the dates?


On Sun, Sep 11, 2022 at 9:47 AM Muhammad Juwaini Abdul Rahman <
juwa...@gmail.com> wrote:

> Either there's no data for that month or your query is wrongly formatted.
> Probably you can try your query in the shell first.
>
> On Sun, 11 Sept 2022 at 02:12, tech george  wrote:
>
>> Hello Muhammad,
>>
>> I'm choosing dates between 2022-07-01 and 2022-07-30 which have records
>> in the db.
>>
>> I hope i have answered you right.
>>
>>
>> On Sat, Sep 10, 2022 at 8:41 AM Muhammad Juwaini Abdul Rahman <
>> juwa...@gmail.com> wrote:
>>
>>> What's your value of 'fromdate' and 'todate'?
>>>
>>> On Sat, 10 Sept 2022 at 13:27, tech george 
>>> wrote:
>>>
>>>> Hello Carlos,
>>>>
>>>> I have used the code below as you advised by when I filter the table
>>>> comes blank:
>>>>
>>>> query_results = Prescription.objects.filter(date__rang
>>>> e=[fromdate,todate])
>>>>
>>>> Regards,
>>>>
>>>>
>>>> On Fri, Sep 9, 2022 at 6:11 PM carlos  wrote:
>>>>
>>>>> Hello why use raw?
>>>>> query_results = Prescription.objects.filter(date__rang
>>>>> e=[fromdate,todate])
>>>>> if you have any problem with performance hit database use
>>>>> select_related or used m2m field use prefect_related
>>>>> https://docs.djangoproject.com/en/4.1/ref/models/querysets/
>>>>>
>>>>> best!
>>>>>
>>>>> On Fri, Sep 9, 2022 at 7:48 AM tech george 
>>>>> wrote:
>>>>>
>>>>>> Hello friends!
>>>>>>
>>>>>> I am trying to give users an easier way to filter data by date range.
>>>>>>
>>>>>> My views.py code is as below, but unfortunately, it is hiding data
>>>>>> without applying the filter whenever I try to use if, else statements.
>>>>>>
>>>>>> Please advise what I might be doing wrong.
>>>>>>
>>>>>> views.py
>>>>>>
>>>>>> ef referralsReports(request):
>>>>>> if request.method=="POST":
>>>>>> fromdate = request.POST.get('fromdate')
>>>>>> todate = request.POST.get('todate')
>>>>>> searchresults = Prescription.objects.raw('select 
>>>>>> id,description,prescribe,ailment,ailment_2,ailment_3,'
>>>>>>  
>>>>>> 'sickOff,referral,date_precribed,nurse_id,patient_id_id,'
>>>>>>  
>>>>>> 'non_work_related_sickOff from pharmacy_prescription where 
>>>>>> date_precribed '
>>>>>>  'between 
>>>>>> "'+str(fromdate)+'" and "'+str(todate)+'"')
>>>>>> return render(request, 
>>>>>> 'pharmacist_templates/reports/referrals_report.html', {"data": 
>>>>>> searchresults})
>>>>>>
>>>>>> else:
>>>>>> displaydata = 
>>>>>> Prescription.objects.filter(nurse=request.user.pharmacist).order_by('-id')
>>>>>> return render(request, 
>>>>>> 'pharmacist_templates/reports/referrals_report.html', 
>>>>>> {"data":displaydata})
>>>>>>
>>>>>>
>>>>>> template
>>>>>>
>>>>>> [image: image.png]
>>>>>>
>>>>>>
>>>>>> --
>>>>>> 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+unsubscr...@googlegroups.com.
>>>>>> To view this discussion on the web visit
>>>>>> https://groups.google.com/d/msgid/django-users/CADY

Re: Filter by date range

2022-09-11 Thread tech george
I managed to solve the issue.

I was using the wrong keyword to fetch the dates.

Thanks for the support.


On Mon, Sep 12, 2022 at 9:03 AM tech george  wrote:

> Hello,
>
> I have tried debugging as below and it returned data;
>
> search_results =
> Prescription.objects.filter(date_prescribed__range=["2022-07-01",2022-07-30"])
>
> Is there another way i can filter the dates?
>
>
> On Sun, Sep 11, 2022 at 9:47 AM Muhammad Juwaini Abdul Rahman <
> juwa...@gmail.com> wrote:
>
>> Either there's no data for that month or your query is wrongly formatted.
>> Probably you can try your query in the shell first.
>>
>> On Sun, 11 Sept 2022 at 02:12, tech george  wrote:
>>
>>> Hello Muhammad,
>>>
>>> I'm choosing dates between 2022-07-01 and 2022-07-30 which have records
>>> in the db.
>>>
>>> I hope i have answered you right.
>>>
>>>
>>> On Sat, Sep 10, 2022 at 8:41 AM Muhammad Juwaini Abdul Rahman <
>>> juwa...@gmail.com> wrote:
>>>
>>>> What's your value of 'fromdate' and 'todate'?
>>>>
>>>> On Sat, 10 Sept 2022 at 13:27, tech george 
>>>> wrote:
>>>>
>>>>> Hello Carlos,
>>>>>
>>>>> I have used the code below as you advised by when I filter the table
>>>>> comes blank:
>>>>>
>>>>> query_results = Prescription.objects.filter(date__rang
>>>>> e=[fromdate,todate])
>>>>>
>>>>> Regards,
>>>>>
>>>>>
>>>>> On Fri, Sep 9, 2022 at 6:11 PM carlos  wrote:
>>>>>
>>>>>> Hello why use raw?
>>>>>> query_results = Prescription.objects.filter(date__rang
>>>>>> e=[fromdate,todate])
>>>>>> if you have any problem with performance hit database use
>>>>>> select_related or used m2m field use prefect_related
>>>>>> https://docs.djangoproject.com/en/4.1/ref/models/querysets/
>>>>>>
>>>>>> best!
>>>>>>
>>>>>> On Fri, Sep 9, 2022 at 7:48 AM tech george 
>>>>>> wrote:
>>>>>>
>>>>>>> Hello friends!
>>>>>>>
>>>>>>> I am trying to give users an easier way to filter data by date range.
>>>>>>>
>>>>>>> My views.py code is as below, but unfortunately, it is hiding data
>>>>>>> without applying the filter whenever I try to use if, else statements.
>>>>>>>
>>>>>>> Please advise what I might be doing wrong.
>>>>>>>
>>>>>>> views.py
>>>>>>>
>>>>>>> ef referralsReports(request):
>>>>>>> if request.method=="POST":
>>>>>>> fromdate = request.POST.get('fromdate')
>>>>>>> todate = request.POST.get('todate')
>>>>>>> searchresults = Prescription.objects.raw('select 
>>>>>>> id,description,prescribe,ailment,ailment_2,ailment_3,'
>>>>>>>  
>>>>>>> 'sickOff,referral,date_precribed,nurse_id,patient_id_id,'
>>>>>>>  
>>>>>>> 'non_work_related_sickOff from pharmacy_prescription where 
>>>>>>> date_precribed '
>>>>>>>  'between 
>>>>>>> "'+str(fromdate)+'" and "'+str(todate)+'"')
>>>>>>> return render(request, 
>>>>>>> 'pharmacist_templates/reports/referrals_report.html', {"data": 
>>>>>>> searchresults})
>>>>>>>
>>>>>>> else:
>>>>>>> displaydata = 
>>>>>>> Prescription.objects.filter(nurse=request.user.pharmacist).order_by('-id')
>>>>>>> return render(request, 
>>>>>>> 'pharmacist_templates/reports/referrals_report.html', 
>>>>>>> {"data":displaydata})
>>>>>>>
>>>>>>>
>>>>>>> template
>>>>>>>
>>>>>>> [image: image.png

Re: group

2022-09-28 Thread tech george
Please add me:

+254724164862

On Wed, Sep 28, 2022 at 7:13 PM Prince Adedotun 
wrote:

> Add me also...
>
> 08167422287
>
> On Mon, 26 Sept 2022, 18:49 yassin kamanyile, 
> wrote:
>
>> Add me +255763023477
>>
>> On Mon, 26 Sept 2022, 15:53 Abdulfarid Olakunle, 
>> wrote:
>>
>>> Hello fellow developers, I will be creating a WhatsApp group chat later
>>> in the day, So I will like my fellow Python Django Developers to join the
>>> group. It will be much easier to discuss there and I will sacrifice myself
>>> out for anyone who need my service.
>>>
>>> God bless you all
>>> Enjoy your day
>>> Biliaminu
>>>
>>> --
>>> 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+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CA%2BccuR0goa8Mu9MqNLyZtCAJedHKpVZ6pFfrpXKFJdjaRrgttQ%40mail.gmail.com
>>> 
>>> .
>>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAOyeOe9tKFCogEZv1NfTVVRMpFcXxayH9vp0JU3XYiFO4fYU%2Bw%40mail.gmail.com
>> 
>> .
>>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CACwPRUzeQqxnS_T0kOaepVZiyfp%3DbXA-cWHy2kRpapruxOsmWA%40mail.gmail.com
> 
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADYG20FwOJWisNa%2BS90rbAncG%3DYTx58vU0WcbaiJBdwTvDNf0g%40mail.gmail.com.


Export filtered data

2023-01-19 Thread tech george
Hello,

I have been trying to export filtered table data to excel but was unlucky.

I can filter the table by date range successfully but can export the
filtered data.

Below is my view.py. Please help

def export_sickoff_export(request):
if request.method=="POST":
start_date = request.POST.get('start_date')
end_date = request.POST.get('end_date')
search_results =
Prescription.objects.filter(date_precribed__range=[start_date,end_date])

return render(request,
'pharmacist_templates/reports/referrals_report.html', {"data":
search_results})

response = HttpResponse(content_type='application/ms-excel')
response['Content-Disposition'] = 'attachment;
filename=Referrals & Sick-offs' + \
str(datetime.datetime.now())+'.csv'

wb = xlwt.Workbook(encoding='utf-8')
ws = wb.add_sheet('Prescription,Patients')

#Sheet header, first row
row_num = 0

font_style = xlwt.XFStyle()
font_style.font.bold = True

columns = ['Payroll No', 'First Name', 'Last Name', 'Non Work
Related SickOff', 'Work Related SickOff', 'Referral', 'Remarks',
'Date']

for col_num in range(len(columns)):
ws.write(row_num, col_num, columns[col_num], font_style)

# Sheet body, remaining rows
font_style = xlwt.XFStyle()

rows = 
Prescription.objects.filter(nurse=request.user.pharmacist).values_list('patient_id__reg_no',
'patient_id__first_name', 'patient_id__last_name',
'non_work_related_sickOff', 'work_related_sickOff', 'referral',
'remarks', 'date_precribed')

for row in rows:
row_num += 1
for col_num in range(len(row)):
ws.write(row_num, col_num, str(row[col_num]), font_style)
# for patient in patients:
# writer.writerow(patient)

wb.save(response)
return response

else:
 displaydata =
Prescription.objects.filter(nurse=request.user.pharmacist).order_by('-id')
 return render(request,
'pharmacist_templates/reports/referrals_report.html',
{"data":displaydata})

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADYG20H0kkewMMV4s_Uxbm%2BwS1HYQGtpfRDfWM%3DUMXj%3DeQiKyw%40mail.gmail.com.


Multiple Media_Root

2020-11-22 Thread tech george
Hello,

I am developing an E-Commerce website and I wanted to have a separate
upload folder for my slides and separate folders for other sections of my
site.

Is there a way i can go about it other than using the ascending and
Descending order?

Please advise.

See section of my view.py page.

[image: image.png]

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADYG20EjD6mRidk8LbyE8_8rAMT3z%3DPki0253eEtO4KtXttwPg%40mail.gmail.com.


Re: Multiple Media_Root

2020-11-23 Thread tech george
Thanks for the guide,

Let me try this option then i'll let you know in case I get stuck.

On Mon, Nov 23, 2020 at 4:41 PM Mbah Victor 
wrote:

> Plz can u send me a review of what you what
>
> Victor
>
> On Sun, Nov 22, 2020, 8:05 PM tech george  wrote:
>
>> Hello,
>>
>> I am developing an E-Commerce website and I wanted to have a separate
>> upload folder for my slides and separate folders for other sections of my
>> site.
>>
>> Is there a way i can go about it other than using the ascending and
>> Descending order?
>>
>> Please advise.
>>
>> See section of my view.py page.
>>
>> [image: image.png]
>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CADYG20EjD6mRidk8LbyE8_8rAMT3z%3DPki0253eEtO4KtXttwPg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CADYG20EjD6mRidk8LbyE8_8rAMT3z%3DPki0253eEtO4KtXttwPg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CANTsAyd6cerLF%3DmNEsUWO1xKgUm7meZRBNj0HNg6Zrh0TWFVjA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CANTsAyd6cerLF%3DmNEsUWO1xKgUm7meZRBNj0HNg6Zrh0TWFVjA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADYG20F376ZyLJO7V5xbQn6jffxSzsXDYwAwv-rTehGLzqC74w%40mail.gmail.com.


RE: Page Resoltuon

2020-12-01 Thread tech george
Hello,

I am working on this webapp using a pre designed template.

But my project is too stretched out and can't seem to make it look like the
actual template.

Please advise.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADYG20F-PozrNr5E-BN1%2BwCP4T5buakXVywPJLTGUyziog49_A%40mail.gmail.com.


Re: Python Django Training

2020-12-07 Thread tech george
I want in too

On Mon, 7 Dec 2020, 16:43 Hector Berrones,  wrote:

> I am interested.
>
> On Mon, Dec 7, 2020, 2:09 AM narendra thapa 
> wrote:
>
>> hello please add me also in training group?
>>
>>
>> On Fri, Feb 21, 2020 at 7:27 PM Bharati Nilam 
>> wrote:
>>
>>> Hi,
>>> I also from Hyderabad and I'm also interested in the training. please
>>> tell me how to join?
>>>
>>> Regards,
>>> Bharati
>>>
>>> On Thu, 20 Feb, 2020, 6:19 PM Thiagu Palaniappan, <
>>> thiagarajan@gmail.com> wrote:
>>>
 I'm also interested. Please add me in the group.


 Thanks & Regards,
 Thiagu

 On Mon, Feb 17, 2020 at 12:41 AM Akshay Raul 
 wrote:

> I am interested also. Please let me know the details.
>
> On Sat 1 Feb, 2020, 2:42 PM Srikanth K,  wrote:
>
>> Hi,
>>
>> I am from Hyderabad. I am Python Developer by Profession. I am eager
>> take up any Python , Django Training (online Preferrable or Weekends).
>> Members who require can contact me or share me  there idea.
>>
>> Regards,
>> Srikanth.K
>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CACPyz-gXb7wo9E0Uhs_pnxF9X52uA10__Fq1xt4trjXUaN3ehQ%40mail.gmail.com
>> 
>> .
>>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAEd%2Bv%3D0gE2dEMXKJ0Nm8FcH2ZxUPAdQspkQKB%2Bg5pZbSc_uZnQ%40mail.gmail.com
> 
> .
>


 --

 Thanks & Regards,

 *Thiagu Palaniappan*

 M +91 (0) 9994318799

 *DXC Technology*
 8th Floor, Tower 1 B DLF IT Park, 1/124 - Shivaji Garden, Nandambakkam
 post, Ramapuram, Chennai - 600 089.

 dxc.technology  / Twitter
  / Facebook
  / LinkedIn
 

 --
 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+unsubscr...@googlegroups.com.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/django-users/CAK%3DQXNMzH-iL6BQ3_vfrvTpeY%2BSe5%3DbZm9h5wPW_Dw%2BM2BsvQg%40mail.gmail.com
 
 .

>>> --
>>> 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+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAPGVBeOgomb94NXAm347QqGcJ%3D3MzxULU7eQnY-M56EbC2D9vg%40mail.gmail.com
>>> 
>>> .
>>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAEtntjXVaVAyDCJJzS748zfNVm242U%2B6vsFkynevf5ghnPgDhw%40mail.gmail.com
>> 
>> .
>>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAFFaoULToa26WJCyDWYq9DtrS8WP_1Lz5nF5pGkpuGnnnsycHA%40mail.gmail.com
> 

DoesNotExist at /

2020-12-27 Thread tech george
Hello,

I am getting the error as shown below when uploading my django project to
share hosting. How can I resolve it?

Please advise.

DoesNotExist at /

Currency matching query does not exist.

Request Method: GET
Request URL: http://fullcart.co.ke/
Django Version: 3.0.7
Exception Type: DoesNotExist
Exception Value:

Currency matching query does not exist.

Exception Location:
/home2/fullcart/virtualenv/fullcart/3.7/lib/python3.7/site-packages/django/db/models/query.py
in get, line 417
Python Executable: /home2/fullcart/virtualenv/fullcart/3.7/bin/python3.7
Python Version: 3.7.8
Python Path:

['',
 '/opt/alt/python37/bin',
 '/home2/fullcart/fullcart',
 '/home2/fullcart/virtualenv/fullcart/3.7/lib64/python37.zip',
 '/home2/fullcart/virtualenv/fullcart/3.7/lib64/python3.7',
 '/home2/fullcart/virtualenv/fullcart/3.7/lib64/python3.7/lib-dynload',
 '/opt/alt/python37/lib64/python3.7',
 '/opt/alt/python37/lib/python3.7',
 '/home2/fullcart/virtualenv/fullcart/3.7/lib/python3.7/site-packages']

Server time: Mon, 28 Dec 2020 07:00:13 +
Error during template rendering

In template /home2/fullcart/fullcart/home/templates/slider.html, error at
line *18*
Currency matching query does not exist.
8 
9 
10 
11
12 {% for rs in products_slider %}
13 
14 
15 
16 
17 {{ rs.title }} 
18  {{
rs.price|currency:request.session.currency }} {{ request.session.currency
}} 
19 Shop Now
20
21 
22 
23 
24 {% endfor %}

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADYG20Hfxc4xK0tDs-%2B326_dS%2BobsNAzaYKOBSYnpg9b8ykprg%40mail.gmail.com.


Re: DoesNotExist at /

2020-12-28 Thread tech george
Hi,

Yes I does.

On Mon, 28 Dec 2020, 18:41 AMRIT SHAHI,  wrote:

> Is your hosting support python
>
> On Mon, Dec 28, 2020, 12:49 PM tech george  wrote:
>
>> Hello,
>>
>> I am getting the error as shown below when uploading my django project to
>> share hosting. How can I resolve it?
>>
>> Please advise.
>>
>> DoesNotExist at /
>>
>> Currency matching query does not exist.
>>
>> Request Method: GET
>> Request URL: http://fullcart.co.ke/
>> Django Version: 3.0.7
>> Exception Type: DoesNotExist
>> Exception Value:
>>
>> Currency matching query does not exist.
>>
>> Exception Location: 
>> /home2/fullcart/virtualenv/fullcart/3.7/lib/python3.7/site-packages/django/db/models/query.py
>> in get, line 417
>> Python Executable: /home2/fullcart/virtualenv/fullcart/3.7/bin/python3.7
>> Python Version: 3.7.8
>> Python Path:
>>
>> ['',
>>  '/opt/alt/python37/bin',
>>  '/home2/fullcart/fullcart',
>>  '/home2/fullcart/virtualenv/fullcart/3.7/lib64/python37.zip',
>>  '/home2/fullcart/virtualenv/fullcart/3.7/lib64/python3.7',
>>  '/home2/fullcart/virtualenv/fullcart/3.7/lib64/python3.7/lib-dynload',
>>  '/opt/alt/python37/lib64/python3.7',
>>  '/opt/alt/python37/lib/python3.7',
>>  '/home2/fullcart/virtualenv/fullcart/3.7/lib/python3.7/site-packages']
>>
>> Server time: Mon, 28 Dec 2020 07:00:13 +
>> Error during template rendering
>>
>> In template /home2/fullcart/fullcart/home/templates/slider.html, error
>> at line *18*
>> Currency matching query does not exist.
>> 8 
>> 9 
>> 10 
>> 11
>> 12 {% for rs in products_slider %}
>> 13 
>> 14 
>> 15 
>> 16 
>> 17 {{ rs.title }} 
>> 18  {{
>> rs.price|currency:request.session.currency }} {{
>> request.session.currency }} 
>> 19 > class="primary-btn">Shop Now
>> 20
>> 21 
>> 22 
>> 23 
>> 24 {% endfor %}
>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CADYG20Hfxc4xK0tDs-%2B326_dS%2BobsNAzaYKOBSYnpg9b8ykprg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CADYG20Hfxc4xK0tDs-%2B326_dS%2BobsNAzaYKOBSYnpg9b8ykprg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CADydCv-oUMh-jkoSLMb_JhEG3sJdA13dvd%2Bo_rFraMaoELGV8g%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CADydCv-oUMh-jkoSLMb_JhEG3sJdA13dvd%2Bo_rFraMaoELGV8g%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADYG20FkcD51rBe9a4%3DUCC7g%2B_PuLtWDAJU3oRbSV5NSypwr_w%40mail.gmail.com.


Re: DoesNotExist at /

2020-12-28 Thread tech george
Hi,


Let me go through the dock and see if I'll get a breakthrough.

Thanks

On Mon, 28 Dec 2020, 18:41 Prashanjeet Halder, 
wrote:

> There's no built-in filter as currency in django template language you can
> custom create one.
>
> *As Demonstrated Here: LINK
> *
>
> On Monday, December 28, 2020 at 12:35:08 PM UTC+5:30 techg...@gmail.com
> wrote:
>
>> Hello,
>>
>> I am getting the error as shown below when uploading my django project to
>> share hosting. How can I resolve it?
>>
>> Please advise.
>>
>> DoesNotExist at /
>>
>> Currency matching query does not exist.
>>
>> Request Method: GET
>> Request URL: http://fullcart.co.ke/
>> Django Version: 3.0.7
>> Exception Type: DoesNotExist
>> Exception Value:
>>
>> Currency matching query does not exist.
>>
>> Exception Location: 
>> /home2/fullcart/virtualenv/fullcart/3.7/lib/python3.7/site-packages/django/db/models/query.py
>> in get, line 417
>> Python Executable: /home2/fullcart/virtualenv/fullcart/3.7/bin/python3.7
>> Python Version: 3.7.8
>> Python Path:
>>
>> ['',
>>  '/opt/alt/python37/bin',
>>  '/home2/fullcart/fullcart',
>>  '/home2/fullcart/virtualenv/fullcart/3.7/lib64/python37.zip',
>>  '/home2/fullcart/virtualenv/fullcart/3.7/lib64/python3.7',
>>  '/home2/fullcart/virtualenv/fullcart/3.7/lib64/python3.7/lib-dynload',
>>  '/opt/alt/python37/lib64/python3.7',
>>  '/opt/alt/python37/lib/python3.7',
>>  '/home2/fullcart/virtualenv/fullcart/3.7/lib/python3.7/site-packages']
>>
>> Server time: Mon, 28 Dec 2020 07:00:13 +
>> Error during template rendering
>>
>> In template /home2/fullcart/fullcart/home/templates/slider.html, error
>> at line *18*
>> Currency matching query does not exist.
>> 8 
>> 9 
>> 10 
>> 11
>> 12 {% for rs in products_slider %}
>> 13 
>> 14 
>> 15 
>> 16 
>> 17 {{ rs.title }} 
>> 18  {{
>> rs.price|currency:request.session.currency }} {{
>> request.session.currency }} 
>> 19 > class="primary-btn">Shop Now
>> 20
>> 21 
>> 22 
>> 23 
>> 24 {% endfor %}
>>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/e17e0564-d639-47d9-b359-8e8f6fa695ccn%40googlegroups.com
> 
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADYG20HNJ5RmyR%2BaMpoAfkhoM68_02QM-rvOxB2_%2BvhbpKjVZQ%40mail.gmail.com.


Re: Product Categories

2021-05-23 Thread tech george
Thanks Work,

Let me try that.

Regards.

On Sat, 22 May 2021, 21:48 N'BE SORO,  wrote:

> Ok use:
>
> # In Python
> # print(category.get_ancestors())
> # In Jinja category.get_ancestors
>
> Le sam. 22 mai 2021 à 18:14, Patrick Café  a
> écrit :
>
>> OK thank you
>>
>> tech george  schrieb am Sa., 22. Mai 2021, 19:11:
>>
>>> Hi Soro,
>>>
>>> Is there a way I can fetch the data without using MPTT?
>>>
>>>
>>> On Sat, May 22, 2021 at 6:31 PM N'BE SORO  wrote:
>>>
>>>> Hi,
>>>> if you use MPTT templates, in your template use {% load mptt_tags %}
>>>>
>>>> And you can proceed as follows for the display
>>>>
>>>> {% load mptt_tags %}
>>>> {% recursetree genres %}
>>>> 
>>>> {{ node.name }}
>>>> {% if not node.is_leaf_node %}
>>>> 
>>>>     {{ children }}
>>>> 
>>>> {% endif %}
>>>> 
>>>> {% endrecursetree %}
>>>>
>>>> 
>>>>
>>>>
>>>> source: https://django-mptt.readthedocs.io/en/latest/tutorial.html
>>>>
>>>> Le ven. 21 mai 2021 à 18:30, tech george  a
>>>> écrit :
>>>>
>>>>> Hello,
>>>>>
>>>>> I need your help with rendering main category products only to the
>>>>> page, currently the code seems to be picking even sub category products.
>>>>>
>>>>> Please see below screenshots.
>>>>>
>>>>>
>>>>> [image: category model.png]
>>>>> [image: category model 2.png]
>>>>>
>>>>> [image: views.png]
>>>>> [image: category products.png]
>>>>>
>>>>> [image: category.html code.png]
>>>>>
>>>>> Please advise.
>>>>>
>>>>> --
>>>>> 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+unsubscr...@googlegroups.com.
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/d/msgid/django-users/CADYG20H6qB4GTVq1J%3D6GcR%2BEu_r53pk-X%3DKvbosMrRrVz9jLYQ%40mail.gmail.com
>>>>> <https://groups.google.com/d/msgid/django-users/CADYG20H6qB4GTVq1J%3D6GcR%2BEu_r53pk-X%3DKvbosMrRrVz9jLYQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>> --
>>>> 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+unsubscr...@googlegroups.com.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/django-users/CAOtSHp_ka4EERa%2B0hfJapGUNMRwziSe0S5xphDU92f9fzjjg3Q%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/django-users/CAOtSHp_ka4EERa%2B0hfJapGUNMRwziSe0S5xphDU92f9fzjjg3Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>> --
>>> 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+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CADYG20EJE7hdVyFz%3D0-a-0QQyTfVR8OBPHDe24i3CFQFMA5cmw%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CADYG20EJE7hdVyFz%3D0-a-0QQyTfVR8OBPHDe24i3CFQFMA5cmw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAA%2B%2BAZxavstcDeL-fMKgtU%2BjnQDznwmm6cfYXDkv-d46OvvRjg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAA%2B%2BAZxavstcDeL-fMKgtU%2BjnQDznwmm6cfYXDkv-d46OvvRjg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAOtSHp9wDcmdSg%3DM8JEzM%3DuuhMVFgers0uST5k-EqB37iZKvJg%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAOtSHp9wDcmdSg%3DM8JEzM%3DuuhMVFgers0uST5k-EqB37iZKvJg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADYG20Gx0dPBjqG4RD0TtkZMDhmHY1Jpza74LDspE2N4fpwSqA%40mail.gmail.com.