Re: Multiple Templates in single list view

2021-11-21 Thread David Nugent
Well, there are several ways you can deal with that.

Probably easiest is to override get_template() and switch the template
based on whatever type of ticket you're managing or you can change the
value of self.template_name based on the request.

Or maybe you prefer a single template to deal with all cases with
conditional blocks where appropriate.


Regards,
David

-- 
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/CAE5VhgUCCnmkm%2BBe0EWLK4Nb%3DXUOHZAEYGax%2B2%2B-kCysYxdzHA%40mail.gmail.com.


Re: Multiple Templates in single list view

2021-11-21 Thread Trippy Samurai
What about the templates i have three different templates for as u can see 
in template_name in the above views ,how do i deal with it if i actualyl 
had one template the above could have worked.
On Monday, 22 November 2021 at 12:42:59 UTC+5:30 sutharl...@gmail.com wrote:

> we can go like 
>
> ```
>
> class Manager(...):
> def get_context_data(self, **kwargs):
> context = super() 
> context["open_tickets"] = Ticket.objects.filter(status="OPEN")
> context["accepted_tickets"] = Ticket.objects.filter(status="ACCEPTED")
> context["completed_tickets"] = Ticket.objects.filter(status="COMPLETED")
> return context
> ```
>
> On Mon, 22 Nov 2021 at 12:19, Trippy Samurai  
> wrote:
>
>> Hi Elena Thanks for the reply i have three different html pages to 
>> display open tickets closed tickets accepted tickets etc each of them have 
>> different ticket statuses i have them written in different views as above 
>> to display each type of ticket at different pages how can i combine all 
>> three in  a single view so that i dont repeat my logic in views.Is there a 
>> way to acheive all the three views writing in a single view?
>>
>> On Monday, 22 November 2021 at 10:04:14 UTC+5:30 elena wrote:
>>
>>> Hi,
>>>
>>> The problem is it's unclear what your question is. Can you be clearer 
>>> about what outcome you're trying to achieve? 
>>>
>>>
>>> ---
>>> Elena Williams
>>> Github: elena 
>>>
>>>
>>> On Mon, 22 Nov 2021 at 15:20, Trippy Samurai  
>>> wrote:
>>>
 Any one plz


 On Sunday, 21 November 2021 at 15:09:39 UTC+5:30 Trippy Samurai wrote:

> Hello,
> I have different views for displaying different templates how do i 
> write them into one single Listview so that i can take care of DRY
>
>
> [image: Screenshot 2021-11-21 at 3.08.58 PM.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...@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/django-users/d86e1449-a17e-4e93-9dd2-1fae9a7e91d7n%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...@googlegroups.com.
>>
> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/c5eeae75-7c09-4f7e-928c-d03d5f10165an%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/a000369b-b20f-4737-9bdc-f913f5af0a08n%40googlegroups.com.


Re: Multiple Templates in single list view

2021-11-21 Thread David Nugent
Hi Lalit,

On Mon, Nov 22, 2021 at 6:12 PM Lalit Suthar 
wrote:

> we can go like
>
> ```
>
> class Manager(...):
> def get_context_data(self, **kwargs):
> context = super() 
> context["open_tickets"] = Ticket.objects.filter(status="OPEN")
> context["accepted_tickets"] = Ticket.objects.filter(status="ACCEPTED")
> context["completed_tickets"] = Ticket.objects.filter(status="COMPLETED")
> return context
> ```
>
> 


That is certainly one value solution, though for any call there are
potentially (ignoring cache) 3 db queries.

To avoid that, an arg or kwarg could be passed to the view by implementing
`get` and allowing for it in the associated path in urls.py. This is
typically a better pattern and very similar to what Dango admin does when a
filter is enabled.

I would also avoid the word `Manager` in a CBV, since `Manager` has a
special meaning in Django.

Regards, David

-- 
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/CAE5VhgW3WcZASeOpfqo4_nxzPpZRJZrV-SWAKFByiDG56fxNGQ%40mail.gmail.com.


Re: Multiple Templates in single list view

2021-11-21 Thread Lalit Suthar
we can go like

```

class Manager(...):
def get_context_data(self, **kwargs):
context = super() 
context["open_tickets"] = Ticket.objects.filter(status="OPEN")
context["accepted_tickets"] = Ticket.objects.filter(status="ACCEPTED")
context["completed_tickets"] = Ticket.objects.filter(status="COMPLETED")
return context
```

On Mon, 22 Nov 2021 at 12:19, Trippy Samurai 
wrote:

> Hi Elena Thanks for the reply i have three different html pages to display
> open tickets closed tickets accepted tickets etc each of them have
> different ticket statuses i have them written in different views as above
> to display each type of ticket at different pages how can i combine all
> three in  a single view so that i dont repeat my logic in views.Is there a
> way to acheive all the three views writing in a single view?
>
> On Monday, 22 November 2021 at 10:04:14 UTC+5:30 elena wrote:
>
>> Hi,
>>
>> The problem is it's unclear what your question is. Can you be clearer
>> about what outcome you're trying to achieve?
>>
>>
>> ---
>> Elena Williams
>> Github: elena 
>>
>>
>> On Mon, 22 Nov 2021 at 15:20, Trippy Samurai 
>> wrote:
>>
>>> Any one plz
>>>
>>>
>>> On Sunday, 21 November 2021 at 15:09:39 UTC+5:30 Trippy Samurai wrote:
>>>
 Hello,
 I have different views for displaying different templates how do i
 write them into one single Listview so that i can take care of DRY


 [image: Screenshot 2021-11-21 at 3.08.58 PM.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...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/d86e1449-a17e-4e93-9dd2-1fae9a7e91d7n%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/c5eeae75-7c09-4f7e-928c-d03d5f10165an%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/CAGp2JVHGLavBh8sZLqepP5QMcQYVdv1m0_AO_rKK0PAHun1NGA%40mail.gmail.com.


Re: Multiple Templates in single list view

2021-11-21 Thread Trippy Samurai
Hi Elena Thanks for the reply i have three different html pages to display 
open tickets closed tickets accepted tickets etc each of them have 
different ticket statuses i have them written in different views as above 
to display each type of ticket at different pages how can i combine all 
three in  a single view so that i dont repeat my logic in views.Is there a 
way to acheive all the three views writing in a single view?

On Monday, 22 November 2021 at 10:04:14 UTC+5:30 elena wrote:

> Hi,
>
> The problem is it's unclear what your question is. Can you be clearer 
> about what outcome you're trying to achieve? 
>
>
> ---
> Elena Williams
> Github: elena 
>
>
> On Mon, 22 Nov 2021 at 15:20, Trippy Samurai  
> wrote:
>
>> Any one plz
>>
>>
>> On Sunday, 21 November 2021 at 15:09:39 UTC+5:30 Trippy Samurai wrote:
>>
>>> Hello,
>>> I have different views for displaying different templates how do i write 
>>> them into one single Listview so that i can take care of DRY
>>>
>>>
>>> [image: Screenshot 2021-11-21 at 3.08.58 PM.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...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/d86e1449-a17e-4e93-9dd2-1fae9a7e91d7n%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/c5eeae75-7c09-4f7e-928c-d03d5f10165an%40googlegroups.com.


Django 4.0 release candidate 1 released

2021-11-21 Thread Mariusz Felisiak

Details are available on the Django project weblog:

https://www.djangoproject.com/weblog/2021/nov/22/django-40-rc1/

--
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/ebe95c76-b281-03fb-e841-79dd16fc76ad%40gmail.com.


Re: Multiple Templates in single list view

2021-11-21 Thread Elena Williams
Hi,

The problem is it's unclear what your question is. Can you be clearer about
what outcome you're trying to achieve?


---
Elena Williams
Github: elena 


On Mon, 22 Nov 2021 at 15:20, Trippy Samurai 
wrote:

> Any one plz
>
>
> On Sunday, 21 November 2021 at 15:09:39 UTC+5:30 Trippy Samurai wrote:
>
>> Hello,
>> I have different views for displaying different templates how do i write
>> them into one single Listview so that i can take care of DRY
>>
>>
>> [image: Screenshot 2021-11-21 at 3.08.58 PM.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/d86e1449-a17e-4e93-9dd2-1fae9a7e91d7n%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/CAMRRKVfEu7vdQsmPr7wD4Ep3j-UhUKwUQqZ5J4yVFAY2JW-TVQ%40mail.gmail.com.


Re: Multiple Templates in single list view

2021-11-21 Thread Trippy Samurai
Any one plz


On Sunday, 21 November 2021 at 15:09:39 UTC+5:30 Trippy Samurai wrote:

> Hello,
> I have different views for displaying different templates how do i write 
> them into one single Listview so that i can take care of DRY
>
>
> [image: Screenshot 2021-11-21 at 3.08.58 PM.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/d86e1449-a17e-4e93-9dd2-1fae9a7e91d7n%40googlegroups.com.


RE: Exported filtered by date data in django

2021-11-21 Thread ngallen4
1.  Declare it on your settings.py 

#settings.py

FOO = “foo”

 �

When you want to use it

e.g views.py

from django.conf import settings

FOO_VARIABLES = settings.FOO

 �

2.  Declare on .env files(OR using set/export)

BAR = “bar”

To use it

import os

BAR_VARIALBE = os.getenviron.get(“BAR”)

 �

 �

Regards

 �

Ngallen Ramadhan

T: +255 765 889 960 | M: +255 715 200 997

Emial:   
ramad...@maycom.co.tz | Skype: ngallen2

 �

From: django-users@googlegroups.com  On Behalf 
Of Twizerimana Emmanuel
Sent: Sunday, November 21, 2021 10:45 AM
To: django-users@googlegroups.com
Subject: Re: Exported filtered by date data in django

  

hy 

I want to declare global variable that used in many functions in python

can you show me 

  

On Sat, Nov 20, 2021 at 9:49 AM Eugene TUYIZERE mailto:eugenetuyiz...@gmail.com> > wrote:

Dear Ramadhan,

  

Still it does not work

  

On Sat, 20 Nov 2021 at 09:18, ramadhan ngallen mailto:ngall...@gmail.com> > wrote:

Depends on your query filter_val2 should lower than filter_val1 as the range 
start from val2 to val1.  
Otherwise change your parameter from val1 to val2
EXPENSES.objects.filter(Q(created_at__range=[filter_val2,filter_val1]))

On 20 Nov 2021, 10:04 +0300, Eugene TUYIZERE mailto:eugenetuyiz...@gmail.com> >, wrote:

Dear Team,

I am trying to export filtered data from a django model, but I get an empty 
file. But when I remove the filter and add all, it works.

Kindly assist  to know how to export filtered data. Below is my code

def  
exportexpenes(request):filter_val1=request.POST.get("filter1")filter_val2=request.POST.get("filter2")response=HttpResponse(content_type='text/csv')response['Content-Disposition']
 =  'attachment; filename=expenses'  +  
str(datetime.datetime.now())+'.csv'writer  =  
csv.writer(response)writer.writerow(['Category','Beneficiary','Description','Operation
 Date','Amount','Account Number','Paymrnt Date','Status'])expes  =  
EXPENSES.objects.filter(Q(created_at__range=[filter_val2,filter_val1]))# expes 
= EXPENSES.objects.all()for  exp  in  
expes:writer.writerow([exp.category,exp.beneficiary,exp.description,exp.date_of_operation,exp.amount,exp.account_number,exp.payment_date,exp.status])return
  response
regards,  
--
Eugene

  --
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/CABxpZHuqV0Py%3D05eyu%3Dv%3DDFBm%2B1y9v-e2AbmVn2Bvj66jG8MZA%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/93a559c8-bc77-44b7-8499-469db0f224e5%40Spark
 

 .




  

-- 

TUYIZERE Eugene

Msc Degree in Mathematical Science

African Institute for Mathematical Sciences (AIMS Cameroon)
Crystal Garden-Lime, Cameroon

Bsc in Computer Science

UR-Nyagatare Campus

  

Email: eugene.tuyiz...@aims-cameroon.org 
 

 eugenetuyiz...@gmail.com  

Tel: (+250) 7 88 26 33 38, (+250) 7 22 26 33 38

-- 
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/CABxpZHvFzd3N1ur5%3DbzmDtJUUAF3BfjamMg7pra-RCL5ffjZCw%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/CAKHnA%2BXTpYHy%2BDDmwe1vpcpLKScp2NLbS0gN_TAiqE_i-mkDCA%40mail.gmail.com