If Statement django template

2023-01-12 Thread 'dtdave' via Django users
I have the following relationship in a model

class Contract(models.Model):
supplier = models.ForeignKey(
Supplier,
on_delete=models.CASCADE,
verbose_name="Supplier Name",
related_name="contract_suppliers",
)

I am trying to include an if statement in my template but the following 
does not work:
{% if contract.supplier == 'IBM' %}

If I replace this with a non-foreign key item then it works fine.

Any help would be 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/4343a170-b193-4c91-aac4-8d773404353dn%40googlegroups.com.


Re: If Statement django template

2023-01-12 Thread Peter Benjamin Ani
why using a foreignkey then? what type of relationship is existing between
the supplier and the

On Thu, Jan 12, 2023 at 2:13 PM 'dtdave' via Django users <
django-users@googlegroups.com> wrote:

> I have the following relationship in a model
>
> class Contract(models.Model):
> supplier = models.ForeignKey(
> Supplier,
> on_delete=models.CASCADE,
> verbose_name="Supplier Name",
> related_name="contract_suppliers",
> )
>
> I am trying to include an if statement in my template but the following
> does not work:
> {% if contract.supplier == 'IBM' %}
>
> If I replace this with a non-foreign key item then it works fine.
>
> Any help would be 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/4343a170-b193-4c91-aac4-8d773404353dn%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/CAPxt_2WpMVk%2Bzsw_useriH4GfGq0k1O5MisHbObcZ%2BCvR3hw%2Bg%40mail.gmail.com.


Re: If Statement django template

2023-01-12 Thread Namanya Daniel
Replace supplier with related_name

On Thu, 12 Jan 2023 at 16:13, 'dtdave' via Django users <
django-users@googlegroups.com> wrote:

> I have the following relationship in a model
>
> class Contract(models.Model):
> supplier = models.ForeignKey(
> Supplier,
> on_delete=models.CASCADE,
> verbose_name="Supplier Name",
> related_name="contract_suppliers",
> )
>
> I am trying to include an if statement in my template but the following
> does not work:
> {% if contract.supplier == 'IBM' %}
>
> If I replace this with a non-foreign key item then it works fine.
>
> Any help would be 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/4343a170-b193-4c91-aac4-8d773404353dn%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/CAP4VW2V7HfijNHaCX5G_6ACmkQwLvHVXK%2BfgVdMEjTUOF8jYKA%40mail.gmail.com.


HOW TO OUTPUT DATA GOT FROM combined queryset IN DJANGO TEMPLATE (html file) ?

2023-01-12 Thread Byansi Samuel
Hey!  Am having a problem. And l request for your Help.

Am having 3 apps in Django project
- action
- adventure
- others


#action/ models.py


class Action(models.Model):
name=models.Charfield()
os= models.Charfield( choices=OS)



#adventure/models.py



class Adventure(models.Model):
 name=models.Charfield()
 os= models.Charfield( choices=OS)



#Others/views.py


from itertools import chain

from action.models import Action

from adventure.models import Adventure


def windows_games(request):

win_action = Action.objects.filter(os='windows')

win_adventure = Adventure.objects.filter(os='windows')
combined_list = list(chain(win_action,win_adventure))

context = ['combined_list':combined_list,]

 return render(request, 'others/os/windows_game.html' , context)



#others/os/windows_game.html

.

 
 {{combined_list.name}}
.








1). I need to correct me in #others/ views.py  if there is any mistake done.

2). I would like to know how to know how to write the tag that outputs the
results in #others/os/windows_game.html because I tried that but outputs
nothing.
And l would like to be in form of,
#{{combined_list.game_pic}}, etc


Please help me.
I'm Samuel

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


Django-annotate(),Count()

2023-01-12 Thread Priya
Hi Everyone,

This is the output i get used this code 

https://groups.google.com/d/msgid/django-users/95dedc5d-5f24-4b57-b525-248c01953bddn%40googlegroups.com.


How to create an registration form and generate qr code for it

2023-01-12 Thread Chandresh . T
Hi friends myself chandresh I am new Django community I have a doubt to be 
cleared ,

So I wanted to create an platform where you can register  users name, 
state, city and photo 
which would also store in Mysql database. Can anyone help me in creating 
this platform.

-- 
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/08434ec2-f7af-4e79-80dc-9c95961082bdn%40googlegroups.com.


Re: If Statement django template

2023-01-12 Thread Peter Benjamin Ani
Have you figured out a solution to it?

On Thu, 12 Jan 2023, 15:52 Namanya Daniel, 
wrote:

>
> Replace supplier with related_name
>
> On Thu, 12 Jan 2023 at 16:13, 'dtdave' via Django users <
> django-users@googlegroups.com> wrote:
>
>> I have the following relationship in a model
>>
>> class Contract(models.Model):
>> supplier = models.ForeignKey(
>> Supplier,
>> on_delete=models.CASCADE,
>> verbose_name="Supplier Name",
>> related_name="contract_suppliers",
>> )
>>
>> I am trying to include an if statement in my template but the following
>> does not work:
>> {% if contract.supplier == 'IBM' %}
>>
>> If I replace this with a non-foreign key item then it works fine.
>>
>> Any help would be 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/4343a170-b193-4c91-aac4-8d773404353dn%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/CAP4VW2V7HfijNHaCX5G_6ACmkQwLvHVXK%2BfgVdMEjTUOF8jYKA%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/CAPxt_2Uu5ed-AwG4fC_72Ly8MYVm-n5Wio_Sp3jafSd0wqbwpg%40mail.gmail.com.


Re: If Statement django template

2023-01-12 Thread Precious Olusola
The supplier field in contract is an instance of a Supplier object which is
not a string, so comparing it to a string won't work, instead compare a
field of the supplier instance in the supplier field in contract instance.

Like: {% if contract.supplier.name == "IBM"%}

Do you get it?


On Thu, Jan 12, 2023, 2:13 PM 'dtdave' via Django users <
django-users@googlegroups.com> wrote:

> I have the following relationship in a model
>
> class Contract(models.Model):
> supplier = models.ForeignKey(
> Supplier,
> on_delete=models.CASCADE,
> verbose_name="Supplier Name",
> related_name="contract_suppliers",
> )
>
> I am trying to include an if statement in my template but the following
> does not work:
> {% if contract.supplier == 'IBM' %}
>
> If I replace this with a non-foreign key item then it works fine.
>
> Any help would be 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/4343a170-b193-4c91-aac4-8d773404353dn%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/CADGG_A%3DMaFuX%2B%3DUM0xyyCud1E%3DkmMFOPFeZXih4fQvoYyfy5Kw%40mail.gmail.com.


Re: If Statement django template

2023-01-12 Thread ASAMOAH EMMANUEL
You can't compare the `contract.supplier` attribute directly to a string
like 'IBM', because it is a foreign key to a `Supplier` model instance.
Instead, you need to access the related `Supplier` model's attributes to
compare them. For example, if the `Supplier` model has a `name` attribute,
you can use:

{% if contract.supplier.name == 'IBM' %}
Alternatively, you could also use a `filter()` method on your `QuerySet` to
filter the contracts by their supplier name before passing them to the
template.

contracts = Contract.objects.filter(supplier__name='IBM')
Then you don't need to use the if statement in the template.

{% for contract in contracts %}

On Thu, Jan 12, 2023 at 2:52 PM Namanya Daniel 
wrote:

>
> Replace supplier with related_name
>
> On Thu, 12 Jan 2023 at 16:13, 'dtdave' via Django users <
> django-users@googlegroups.com> wrote:
>
>> I have the following relationship in a model
>>
>> class Contract(models.Model):
>> supplier = models.ForeignKey(
>> Supplier,
>> on_delete=models.CASCADE,
>> verbose_name="Supplier Name",
>> related_name="contract_suppliers",
>> )
>>
>> I am trying to include an if statement in my template but the following
>> does not work:
>> {% if contract.supplier == 'IBM' %}
>>
>> If I replace this with a non-foreign key item then it works fine.
>>
>> Any help would be 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/4343a170-b193-4c91-aac4-8d773404353dn%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/CAP4VW2V7HfijNHaCX5G_6ACmkQwLvHVXK%2BfgVdMEjTUOF8jYKA%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/CABFHQYw8jQObsCMUX4poRMRTtb0g0ph2f%2BjNrrdvnbfNu2Eq5Q%40mail.gmail.com.