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.


check_file_based_cache_is_absolute doesn't close caches

2023-01-19 Thread Nikita Manovich
Hi,

Why check_file_based_cache_is_absolute doesn't close cache? Does Django 
have any reasons for that?

I expect that 
in 
https://github.com/django/django/blob/4b066bde692078b194709d517b27e55defae787c/django/core/checks/caches.py#L62
 
function each cache will be closed before continue statement.

For example, DjangoCache initializes SQLite DB. Our project has multiple RQ 
workers. Each of them keeps the DB open till its death.

--
  Nikita

-- 
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/542a64ac-77f5-472c-a533-4af24db87618n%40googlegroups.com.


Re: Multitenant app // Validation / constraints for related fields

2023-01-19 Thread ASAMOAH EMMANUEL
One other approach you could consider is using Django's built-in form and
model validation. You could create a custom form class that inherits from
the built-in Django `ModelForm` and override the `clean` method to perform
your tenant check.
For example:

class BlogPostForm(forms.ModelForm):
def clean(self):
cleaned_data = super().clean()
if cleaned_data.get('organization') !=
cleaned_data.get('lead_author').organization:
raise forms.ValidationError("Organization of the post and lead
author must match.")
return cleaned_data


You could then use this form in your views to handle the validation before
saving the model to the database.
Another approach could be to use Django's `clean_fields()` method to
validate that the fields you want to check match. for example:

class BlogPost(models.Model):
organization = models.ForeignKey(to=Organization,
on_delete=models.CASCADE)
lead_author = models.ForeignKey(to=Author, on_delete=models.CASCADE)
slug = models.SlugField(max_length=64)

def clean_fields(self, exclude=None):
super().clean_fields(exclude=exclude)
if self.organization != self.lead_author.organization:
raise ValidationError("Organization of the post and lead author
must match.")

It's worth noting that this approach will run the validation method on each
save, so it may cause a performance hit if you are saving large number of
records.
In any case, it is essential to test the different options and measure
their performance to decide which one is better for your use case.

On Thu, Jan 19, 2023 at 1:21 PM Abeed Visram  wrote:

> Hi there,
>
> Long-time lurker / Django user; first-time poster.
>
> Ask: Any other ideas for ensuring that ForeignKey relationships are valid?
>
> Context / background: I'm working on a multitenant app, and looking at
> ways of ensuring the integrity of the data in the system. Specifically, I
> want to ensure that for a "tenant'ed" model that contains ForeignKey
> fields, those FK relations match the same tenant.
>
> Unfortunately CHECK constraints aren't suitable, as these are limited to
> just the row being inserted/updated, so nested SELECTs or similar at the
> database level aren't possible. It seems as if a TRIGGER could do the job,
> but I'm wary of going down this path if there are other solutions that I've
> missed.
>
> At present I've implemented something along the following simplified lines
> within the application.
>
> All ideas greatly appreciated. Thanks in advance :)
>
> # models.py
> class BaseModel(models.Model):
> match_fields: List[List[str]] = []
>
> class Meta:
> abstract = True
>
> def clean(self):
> self.validate_matching_fields()
> return super().clean()
>
> def validate_matching_fields(self) -> None:
> for field_names in self.match_fields:
> field_values: Dict[str, Any] = dict()
> for field_name in field_names:
> value = self
> for field in field_name.split("."):
> value = getattr(value, field)
> field_values[field_name] = value
> _values = list(field_values.values())
> assert len(_values) > 1
> values_equal = all([V == _values[0] for V in _values])
> if not values_equal:  # pragma: no branch
> msg = f"One or more required fields not matching:
> {field_values}."
> raise ValidationError(msg)
> return
>
> # Tenant model
> class Organization(models.Model):
> name = models.CharField(max_length=64)
>
> class Author(models.Model):
> organization = models.ForeignKey(to=Organization,
> on_delete=models.CASCADE)
> name = models.CharField(max_length=64)
>
> # Target model
> # I want to ensure that BlogPost.organization ==
> BlogPost.lead_author.organization
> class BlogPost(BaseModel):
> match_fields = [["organization.id", "lead_author.organization.id"]]
>
> organization = models.ForeignKey(to=Organization,
> on_delete=models.CASCADE)
> lead_author = models.ForeignKey(to=Author, on_delete=models.CASCADE)
> slug = models.SlugField(max_length=64)
>
> --
> 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/18fe8095-3f46-44e6-b418-49e6a411667cn%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 

Re: AttributeError: 'QuerySet' object has no attribute 'mime_type'

2023-01-19 Thread Jason
is `content` a queryset? 

On Thursday, January 19, 2023 at 8:21:39 AM UTC-5 monisha.s...@ideas2it.com 
wrote:

> @staticmethod
> def post(request, *args, **kwargs):
> constant = utils.send_grid_key
> sg = SendGridAPIClient(constant)
> subject = get_subject()
> content = get_content()
> message = Mail(
> from_email=From((utils.sender_mail, 'Hello')),
> to_emails=To('man...@gmail.com'),
> # to_emails=To(get_email()),
> subject=subject,
> html_content=content)
> response = sg.send(message)
> print(response.status_code)
> print(response.body)
> print(response.headers)
> return Response(response)
>
>
> Traceback (most recent call last):
>   File 
> "C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\django\core\handlers\exception.py",
>  
> line 55, in inner
> response = get_response(request)
>^
>   File 
> "C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\django\core\handlers\base.py",
>  
> line 197, in _get_response
> response = wrapped_callback(request, *callback_args, **callback_kwargs)
>
>   File 
> "C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\django\views\decorators\csrf.py",
>  
> line 54, in wrapped_view
> return view_func(*args, **kwargs)
>^^
>   File 
> "C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\django\views\generic\base.py",
>  
> line 103, in view
> return self.dispatch(request, *args, **kwargs)
>^^^
>   File 
> "C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\rest_framework\views.py",
>  
> line 509, in dispatch
> response = self.handle_exception(exc)
>^^
>   File 
> "C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\rest_framework\views.py",
>  
> line 469, in handle_exception
> self.raise_uncaught_exception(exc)
>   File 
> "C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\rest_framework\views.py",
>  
> line 480, in raise_uncaught_exception
> raise exc
>   File 
> "C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\rest_framework\views.py",
>  
> line 506, in dispatch
> response = handler(request, *args, **kwargs)
>^
>   File "C:\Users\Lenovo\marketautomation\automation\user\views.py", line 
> 140, in post
> message = Mail(
>   ^
>   File 
> "C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\sendgrid\helpers\mail\mail.py",
>  
> line 80, in __init__
> self.add_content(html_content, MimeType.html)
>   File 
> "C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\sendgrid\helpers\mail\mail.py",
>  
> line 734, in add_content
> if content.mime_type == MimeType.text:
>^
> AttributeError: 'QuerySet' object has no attribute 'mime_type'
> [19/Jan/2023 17:54:52] ERROR - Internal Server Error: /automation/user/mail
> Traceback (most recent call last):
>   File 
> "C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\django\core\handlers\exception.py",
>  
> line 55, in inner
> response = get_response(request)
>^
>   File 
> "C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\django\core\handlers\base.py",
>  
> line 197, in _get_response
> response = wrapped_callback(request, *callback_args, **callback_kwargs)
>
>   File 
> "C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\django\views\decorators\csrf.py",
>  
> line 54, in wrapped_view
> return view_func(*args, **kwargs)
>^^
>   File 
> "C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\django\views\generic\base.py",
>  
> line 103, in view
> return self.dispatch(request, *args, **kwargs)
>^^^
>   File 
> "C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\rest_framework\views.py",
>  
> line 509, in dispatch
> response = self.handle_exception(exc)
>^^
>   File 
> "C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\rest_framework\views.py",
>  
> line 469, in handle_exception
> self.raise_uncaught_exception(exc)
>   File 
> "C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\rest_framework\views.py",
>  
> line 480, in raise_uncaught_exception
> raise exc
>   File 
> "C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\rest_framework\views.py",
>  
> line 506, in dispatch
> response = handler(request, *args, **kwargs)
>^
>   File "C:\Users\Lenovo\marketautomation\automation\user\views.py", line 
> 140, in post
> message = Mail(
>   ^
>   File 
> "C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\sendgrid\helpers\mail\mail.py",
>  
> line 80, 

Re: Please i need help in creating a Login page with Django

2023-01-19 Thread M Adnan
Join this group to discuss your issues with developers link below ,


https://chat.whatsapp.com/ICXdXOrbgoNFQTbKxalZD1

On Thu, 19 Jan 2023, 6:21 pm Radhika Soni,  wrote:

> Hello,
> You can take help from udemy or coursera courses.
>
> On Thu, Jan 19, 2023, 4:36 PM Hubert Kanyamahanga 
> wrote:
>
>> Please share what you have been able to do, where you are blocked and
>> from there we can guide you, because, we don't even know which videos you
>> have been viewing!
>>
>> On Wednesday, January 18, 2023 at 11:56:45 PM UTC+1 macca...@gmail.com
>> wrote:
>>
>>> I am trying everything possible to create a basic login page with
>>> Django., i have tried so many videos and online tutorial, but still can't
>>> make anything meaningful out of it. Can anyone please take me through a
>>> systematic process please, since i am new here and want to take Django to
>>> be my friend
>>
>> --
>> 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/61f6c9f9-2973-4572-ae51-8689d6521292n%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/CAGhU6zNsAmutLvJRFdHMPOU8ZKS4Oywha%2B%3DoOWkKAUw4tsh61A%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/CABNyTSpXT57HOuVSWcmLk1NxSyq9F8hsZPYiWY0CtSRzk_2KpQ%40mail.gmail.com.


Re: Please i need help in creating a Login page with Django

2023-01-19 Thread ritik sahoo
Ofcourse

On Thu, 19 Jan, 2023, 7:40 pm Sebastian Jung, 
wrote:

> I think this is a good start or?
>
> https://github.com/earthcomfy/Django-registration-and-login-system
>
> Namanya Daniel  schrieb am Do., 19. Jan. 2023,
> 15:00:
>
>> Explain where you’re failing exactly, is it views, forms, templates or
>> models
>>
>> On Thu, 19 Jan 2023 at 01:56, Michael R. KOOMSON 
>> wrote:
>>
>>> I am trying everything possible to create a basic login page with
>>> Django., i have tried so many videos and online tutorial, but still can't
>>> make anything meaningful out of it. Can anyone please take me through a
>>> systematic process please, since i am new here and want to take Django to
>>> be my friend
>>>
>>> --
>>> 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/0c495fc8-ce4e-4d6f-a2d7-7b2d8478b06an%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/CAP4VW2V%3DuVe2p%3DCQJBWup%3DDcn4FGs5dLFp-zGEqXLQK6xwD6VQ%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/CAKGT9mxg9yy3OXojtu67UUSADUbrpYe%2B%2BQT2aFBW6h2tKMGN7w%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/CAJwehCs8e4sZ9wGOoqq_8pA_OS6D%2BQgww2%2B9VvLgtwkV%3DoBWag%40mail.gmail.com.


Re: Please i need help in creating a Login page with Django

2023-01-19 Thread Sebastian Jung
I think this is a good start or?

https://github.com/earthcomfy/Django-registration-and-login-system

Namanya Daniel  schrieb am Do., 19. Jan. 2023,
15:00:

> Explain where you’re failing exactly, is it views, forms, templates or
> models
>
> On Thu, 19 Jan 2023 at 01:56, Michael R. KOOMSON 
> wrote:
>
>> I am trying everything possible to create a basic login page with
>> Django., i have tried so many videos and online tutorial, but still can't
>> make anything meaningful out of it. Can anyone please take me through a
>> systematic process please, since i am new here and want to take Django to
>> be my friend
>>
>> --
>> 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/0c495fc8-ce4e-4d6f-a2d7-7b2d8478b06an%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/CAP4VW2V%3DuVe2p%3DCQJBWup%3DDcn4FGs5dLFp-zGEqXLQK6xwD6VQ%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/CAKGT9mxg9yy3OXojtu67UUSADUbrpYe%2B%2BQT2aFBW6h2tKMGN7w%40mail.gmail.com.


Re: configuration

2023-01-19 Thread Namanya Daniel
Profile, shipments and species are models? Or your stored data in one model

On Thu, 19 Jan 2023 at 01:56, frank dilorenzo  wrote:

> I cannot seem to resolve this configuration correctly.
>
> I have a list of suppliers.
> A supplier can have one profile
> A supplier can have many shipments.
> A shipment can have many species
>
> I have tried several ways and I always end up with some kind of circular
> problem.
> Any thoughts are appreciated.
>
> --
> 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/60f10b20-ddff-46b6-ac89-63756a192831n%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/CAP4VW2UEDkToWe%2BSGLM9ta5UVi39xKG_Nv6roP3EM5EzFveiRg%40mail.gmail.com.


Re: Please i need help in creating a Login page with Django

2023-01-19 Thread Namanya Daniel
Explain where you’re failing exactly, is it views, forms, templates or
models

On Thu, 19 Jan 2023 at 01:56, Michael R. KOOMSON 
wrote:

> I am trying everything possible to create a basic login page with Django.,
> i have tried so many videos and online tutorial, but still can't make
> anything meaningful out of it. Can anyone please take me through a
> systematic process please, since i am new here and want to take Django to
> be my friend
>
> --
> 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/0c495fc8-ce4e-4d6f-a2d7-7b2d8478b06an%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/CAP4VW2V%3DuVe2p%3DCQJBWup%3DDcn4FGs5dLFp-zGEqXLQK6xwD6VQ%40mail.gmail.com.


Re: Please i need help in creating a Login page with Django

2023-01-19 Thread ritik sahoo
If u will follow geekyshows channel on YouTube your basic must be cleared


On Thu, 19 Jan, 2023, 6:51 pm Radhika Soni,  wrote:

> Hello,
> You can take help from udemy or coursera courses.
>
> On Thu, Jan 19, 2023, 4:36 PM Hubert Kanyamahanga 
> wrote:
>
>> Please share what you have been able to do, where you are blocked and
>> from there we can guide you, because, we don't even know which videos you
>> have been viewing!
>>
>> On Wednesday, January 18, 2023 at 11:56:45 PM UTC+1 macca...@gmail.com
>> wrote:
>>
>>> I am trying everything possible to create a basic login page with
>>> Django., i have tried so many videos and online tutorial, but still can't
>>> make anything meaningful out of it. Can anyone please take me through a
>>> systematic process please, since i am new here and want to take Django to
>>> be my friend
>>
>> --
>> 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/61f6c9f9-2973-4572-ae51-8689d6521292n%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/CAGhU6zNsAmutLvJRFdHMPOU8ZKS4Oywha%2B%3DoOWkKAUw4tsh61A%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/CAJwehCs3jF8TF5q%2BqY7XvWafPCprs8EtVcUA2oMLvcSUsumsJw%40mail.gmail.com.


Re: Digest for django-users@googlegroups.com - 8 updates in 6 topics

2023-01-19 Thread Rivière Du Changement
i new in django how to  show categorys product in templates , from
views in templates

anyone

2023-01-19 14:01 UTC+01:00, django-users@googlegroups.com
:
> =
> Today's topic summary
> =
>
> Group: django-users@googlegroups.com
> Url:
>
> https://groups.google.com/forum/?utm_source=digest_medium=email#!forum/django-users/topics
>
>
>   - Please i need help in creating a Login page with Django [2 Updates]
> http://groups.google.com/group/django-users/t/ec5d94932dcb5e05
>   - thena.thenadaka.com [1 Update]
> http://groups.google.com/group/django-users/t/ed97a2b721fb9928
>   - save() method not working in shell. What are possible causes? [2
> Updates]
> http://groups.google.com/group/django-users/t/1fe591fc862f3584
>   - configuration [1 Update]
> http://groups.google.com/group/django-users/t/c2dc0a80f9eeb51f
>   - How to fetch 1 above record within second in django? [1 Update]
> http://groups.google.com/group/django-users/t/81326751a2a9ece0
>   - Admin validation activated just once after final call to save_model() [1
> Update]
> http://groups.google.com/group/django-users/t/6a50371c45ac7f4e
>
>
> =
> Topic: Please i need help in creating a Login page with Django
> Url: http://groups.google.com/group/django-users/t/ec5d94932dcb5e05
> =
>
> -- 1 of 2 --
> From: "Michael R. KOOMSON" 
> Date: Jan 18 08:12AM -0800
> Url: http://groups.google.com/group/django-users/msg/8873c1411ff5a
>
> I am trying everything possible to create a basic login page with Django.,
> i have tried so many videos and online tutorial, but still can't make
> anything meaningful out of it. Can anyone please take me through a
> systematic process please, since i am new here and want to take Django to
> be my friend
>
>
> -- 2 of 2 --
> From: Hubert Kanyamahanga 
> Date: Jan 19 03:06AM -0800
> Url: http://groups.google.com/group/django-users/msg/8af0f55a7dd29
>
> Please share what you have been able to do, where you are blocked and from
> there we can guide you, because, we don't even know which videos you have
> been viewing!
>
> On Wednesday, January 18, 2023 at 11:56:45 PM UTC+1 macca...@gmail.com
> wrote:
>
>
>
>
> =
> Topic: thena.thenadaka.com
> Url: http://groups.google.com/group/django-users/t/ed97a2b721fb9928
> =
>
> -- 1 of 1 --
> From: Namanya Daniel 
> Date: Jan 19 12:15AM -0800
> Url: http://groups.google.com/group/django-users/msg/8a5bb48015a5f
>
> Hello esteemed members,
>
> I hope all is well. I am reaching out to you today to invite you to check
> out thena.thenadaka.com and give me your honest opinions and guidance.
>
> Is it a good idea for portifolio building, i believe this is important to
> know most especially to us looking for jobs..
>
> Thanks in advance
>
>
>
> =
> Topic: save() method not working in shell. What are possible causes?
> Url: http://groups.google.com/group/django-users/t/1fe591fc862f3584
> =
>
> -- 1 of 2 --
> From: "Artur Rączka" 
> Date: Jan 18 01:25PM -0800
> Url: http://groups.google.com/group/django-users/msg/8873c52a36d03
>
> Hello guys,
>
> What am I missing or doing wrong?
>
 dublin.price
> 40
 dublin.price = 100
 dublin.price
> 100
 dublin.save()
 dublin.price
> 40
>
>
> -- 2 of 2 --
> From: "Artur Rączka" 
> Date: Jan 19 09:02AM +0100
> Url: http://groups.google.com/group/django-users/msg/8a51774ff300c
>
> Ok. I solved the problem myself. The pre_save signal was changing my output
> every time I used save() method.
>
>
> W dniu śr., 18.01.2023 o 23:56 Artur Rączka 
> napisał(a):
>
>
>
>
> =
> Topic: configuration
> Url: http://groups.google.com/group/django-users/t/c2dc0a80f9eeb51f
> =
>
> -- 1 of 1 --
> From: frank dilorenzo 
> Date: Jan 18 01:11PM -0800
> Url: http://groups.google.com/group/django-users/msg/8873cbd078fb8
>
> I cannot seem to resolve this configuration correctly.
>
> I have a list of suppliers.
> A supplier can have one profile
> A supplier can have many shipments.
> A shipment can have many species
>
> I have tried several ways and I always end up with some kind of circular
> problem.
> Any thoughts are appreciated.
>
>
>
> 

AttributeError: 'QuerySet' object has no attribute 'mime_type'

2023-01-19 Thread Monisha Sivanathan
@staticmethod
def post(request, *args, **kwargs):
constant = utils.send_grid_key
sg = SendGridAPIClient(constant)
subject = get_subject()
content = get_content()
message = Mail(
from_email=From((utils.sender_mail, 'Hello')),
to_emails=To('mani...@gmail.com'),
# to_emails=To(get_email()),
subject=subject,
html_content=content)
response = sg.send(message)
print(response.status_code)
print(response.body)
print(response.headers)
return Response(response)


Traceback (most recent call last):
  File 
"C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\django\core\handlers\exception.py",
 
line 55, in inner
response = get_response(request)
   ^
  File 
"C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\django\core\handlers\base.py",
 
line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
   
  File 
"C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\django\views\decorators\csrf.py",
 
line 54, in wrapped_view
return view_func(*args, **kwargs)
   ^^
  File 
"C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\django\views\generic\base.py",
 
line 103, in view
return self.dispatch(request, *args, **kwargs)
   ^^^
  File 
"C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\rest_framework\views.py",
 
line 509, in dispatch
response = self.handle_exception(exc)
   ^^
  File 
"C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\rest_framework\views.py",
 
line 469, in handle_exception
self.raise_uncaught_exception(exc)
  File 
"C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\rest_framework\views.py",
 
line 480, in raise_uncaught_exception
raise exc
  File 
"C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\rest_framework\views.py",
 
line 506, in dispatch
response = handler(request, *args, **kwargs)
   ^
  File "C:\Users\Lenovo\marketautomation\automation\user\views.py", line 
140, in post
message = Mail(
  ^
  File 
"C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\sendgrid\helpers\mail\mail.py",
 
line 80, in __init__
self.add_content(html_content, MimeType.html)
  File 
"C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\sendgrid\helpers\mail\mail.py",
 
line 734, in add_content
if content.mime_type == MimeType.text:
   ^
AttributeError: 'QuerySet' object has no attribute 'mime_type'
[19/Jan/2023 17:54:52] ERROR - Internal Server Error: /automation/user/mail
Traceback (most recent call last):
  File 
"C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\django\core\handlers\exception.py",
 
line 55, in inner
response = get_response(request)
   ^
  File 
"C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\django\core\handlers\base.py",
 
line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
   
  File 
"C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\django\views\decorators\csrf.py",
 
line 54, in wrapped_view
return view_func(*args, **kwargs)
   ^^
  File 
"C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\django\views\generic\base.py",
 
line 103, in view
return self.dispatch(request, *args, **kwargs)
   ^^^
  File 
"C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\rest_framework\views.py",
 
line 509, in dispatch
response = self.handle_exception(exc)
   ^^
  File 
"C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\rest_framework\views.py",
 
line 469, in handle_exception
self.raise_uncaught_exception(exc)
  File 
"C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\rest_framework\views.py",
 
line 480, in raise_uncaught_exception
raise exc
  File 
"C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\rest_framework\views.py",
 
line 506, in dispatch
response = handler(request, *args, **kwargs)
   ^
  File "C:\Users\Lenovo\marketautomation\automation\user\views.py", line 
140, in post
message = Mail(
  ^
  File 
"C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\sendgrid\helpers\mail\mail.py",
 
line 80, in __init__
self.add_content(html_content, MimeType.html)
  File 
"C:\Users\Lenovo\marketautomation\venv\Lib\site-packages\sendgrid\helpers\mail\mail.py",
 
line 734, in add_content
if content.mime_type == MimeType.text:


i dont know how to fix the error, just help me to fix this

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" 

Multitenant app // Validation / constraints for related fields

2023-01-19 Thread Abeed Visram
Hi there,

Long-time lurker / Django user; first-time poster.

Ask: Any other ideas for ensuring that ForeignKey relationships are valid?

Context / background: I'm working on a multitenant app, and looking at ways 
of ensuring the integrity of the data in the system. Specifically, I want 
to ensure that for a "tenant'ed" model that contains ForeignKey fields, 
those FK relations match the same tenant.

Unfortunately CHECK constraints aren't suitable, as these are limited to 
just the row being inserted/updated, so nested SELECTs or similar at the 
database level aren't possible. It seems as if a TRIGGER could do the job, 
but I'm wary of going down this path if there are other solutions that I've 
missed.

At present I've implemented something along the following simplified lines 
within the application.

All ideas greatly appreciated. Thanks in advance :)

# models.py
class BaseModel(models.Model):
match_fields: List[List[str]] = []

class Meta:
abstract = True

def clean(self):
self.validate_matching_fields()
return super().clean()

def validate_matching_fields(self) -> None:
for field_names in self.match_fields:
field_values: Dict[str, Any] = dict()
for field_name in field_names:
value = self
for field in field_name.split("."):
value = getattr(value, field)
field_values[field_name] = value
_values = list(field_values.values())
assert len(_values) > 1
values_equal = all([V == _values[0] for V in _values])
if not values_equal:  # pragma: no branch
msg = f"One or more required fields not matching: 
{field_values}."
raise ValidationError(msg)
return

# Tenant model
class Organization(models.Model):
name = models.CharField(max_length=64)

class Author(models.Model):
organization = models.ForeignKey(to=Organization, 
on_delete=models.CASCADE)
name = models.CharField(max_length=64)

# Target model
# I want to ensure that BlogPost.organization == 
BlogPost.lead_author.organization
class BlogPost(BaseModel):
match_fields = [["organization.id", "lead_author.organization.id"]]

organization = models.ForeignKey(to=Organization, 
on_delete=models.CASCADE)
lead_author = models.ForeignKey(to=Author, on_delete=models.CASCADE)
slug = models.SlugField(max_length=64)

-- 
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/18fe8095-3f46-44e6-b418-49e6a411667cn%40googlegroups.com.


Re: Please i need help in creating a Login page with Django

2023-01-19 Thread Radhika Soni
Hello,
You can take help from udemy or coursera courses.

On Thu, Jan 19, 2023, 4:36 PM Hubert Kanyamahanga 
wrote:

> Please share what you have been able to do, where you are blocked and from
> there we can guide you, because, we don't even know which videos you have
> been viewing!
>
> On Wednesday, January 18, 2023 at 11:56:45 PM UTC+1 macca...@gmail.com
> wrote:
>
>> I am trying everything possible to create a basic login page with
>> Django., i have tried so many videos and online tutorial, but still can't
>> make anything meaningful out of it. Can anyone please take me through a
>> systematic process please, since i am new here and want to take Django to
>> be my friend
>
> --
> 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/61f6c9f9-2973-4572-ae51-8689d6521292n%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/CAGhU6zNsAmutLvJRFdHMPOU8ZKS4Oywha%2B%3DoOWkKAUw4tsh61A%40mail.gmail.com.


Re: Please i need help in creating a Login page with Django

2023-01-19 Thread Hubert Kanyamahanga
Please share what you have been able to do, where you are blocked and from 
there we can guide you, because, we don't even know which videos you have 
been viewing!

On Wednesday, January 18, 2023 at 11:56:45 PM UTC+1 macca...@gmail.com 
wrote:

> I am trying everything possible to create a basic login page with Django., 
> i have tried so many videos and online tutorial, but still can't make 
> anything meaningful out of it. Can anyone please take me through a 
> systematic process please, since i am new here and want to take Django to 
> be my friend

-- 
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/61f6c9f9-2973-4572-ae51-8689d6521292n%40googlegroups.com.


thena.thenadaka.com

2023-01-19 Thread Namanya Daniel
Hello esteemed members,

I hope all is well. I am reaching out to you today to invite you to check 
out thena.thenadaka.com and give me your honest opinions and guidance. 

Is it a good idea for portifolio building, i believe this is important to 
know most especially to us looking for jobs.. 

Thanks in advance

-- 
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/73b703d8-79ca-4277-b735-bc1aa3afbff5n%40googlegroups.com.


Re: save() method not working in shell. What are possible causes?

2023-01-19 Thread Artur Rączka
Ok. I solved the problem myself. The pre_save signal was changing my output
every time I used save() method.


W dniu śr., 18.01.2023 o 23:56 Artur Rączka 
napisał(a):

> Hello guys,
>
> What am I missing or doing wrong?
>
> >>> dublin.price
> 40
> >>> dublin.price = 100
> >>> dublin.price
> 100
> >>> dublin.save()
> >>> dublin.price
> 40
>
>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/H-WR_IYvNYQ/unsubscribe.
> To unsubscribe from this group and all its topics, 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/ca959a16-a448-4e73-8846-fb5cba341f9an%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/CAD2QgpuYzwOhLicc5HXzXO1FqTwAJN3Qm_sAu1wBxoWUC%2BoePg%40mail.gmail.com.