Re: How to retrieve the latest object added (new one) in Django models and display it in the template?

2023-02-28 Thread Andréas Kühne
I'm sorry Dev, but that is really bad practice.

You are doing in python what can be done by the database. That type of code
would create a memory error and be very slow to run. It's much better to
get the last item from the database. In your example it would just be:
last_action = ActionGame.objects.last()


Den tis 28 feb. 2023 kl 15:04 skrev Dev Femi Badmus :

> all_action=ActionGame.objects.all()
> my_action = []
> for action in all_action:
> my_action.append(action)
> last_action = my_action[-1]
>
>
> On Tue, Feb 28, 2023 at 1:05 PM Andréas Kühne 
> wrote:
>
>> Se comments below.
>>
>>
>> Den fre 24 feb. 2023 kl 12:14 skrev Byansi Samuel <
>> samuelbyans...@gmail.com>:
>>
>>> Hey everyone, l got a problem. Am trying to retrieve a single latest
>>> object added everytime, and display it in the template.
>>> Below is my codes but;
>>>
>>> Help me figure it out the source of the problem in these different
>>> instances below 
>>>
>>> ___ issue number 1___
>>>
>>> #Action/models.py
>>> class ActionGame(models.Model):
>>> name=models.Charfield()
>>> published=models.DateTimeField()
>>>
>>> #Action/views.py
>>> from Action.models import ActionGame
>>>
>>> def action (request):
>>> latest_action=ActionGame.objects.filter(published=published).
>>> latest()
>>> Context={ 'latest_action': latest_action }
>>> return
>>>
>>> But it returns *error* :
>>> name 'published' is not defined
>>>
>>
>> You haven't defined what the value of published is. If you want to get
>> the last created one the query should be:
>> latest_action=ActionGame.objects.latest("published") - that would give
>> you the last published item. Another way would be:
>> latest_action=ActionGame.objects.order_by("published").last()
>>
>>
>>>  issue number 2
>>>
>>> #Action/models.py
>>> class ActionGame(models.Model):
>>> name=models.Charfield()
>>> published=models.DateTimeField()
>>> class Meta:
>>>   get_latest_by='published'
>>>
>>> #Action/views.py
>>> 
>>> latest_action=ActionGame.objects. latest()
>>> ...
>>>
>>> #but it returns *error* :
>>> 'ActionGame' object is not iterable
>>>
>>> Even if I try this:
>>> 
>>> latest_action=ActionGame.objects. latest('published')
>>> ...
>>>
>>> #it returns the Same error:
>>> 'ActionGame' object is not iterable
>>>
>>> But this second issue, the error is referred in #action.html
>>>
>>> {% for x in latest _action %}
>>> {{ x.game_name }}
>>> {% endfor %}
>>>
>>>
>> So the latest_action variable that you have sent to the template is an
>> instance of ActionGame - and not a list or anything. You can only access
>> variables in the ActionGame class. For example:
>>
>>  {{ lastest_action.name }}
>>
>> would print out the value of the name of the ActionGame instance.
>>
>> Please l need your assistance.
>>>
>>> I'm Samuel,
>>> Thanks
>>>
>>> --
>>> 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/CAGQoQ3wMUno6hLAO-1FtN0Nn7VtkCn4qf-O4U%3DpeJ4JzY%2B%3DcAQ%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/CAK4qSCeBCST7o-5WZx%2BmhGO2yH-Msdse%3DKusk9UOyW8XZBXRBw%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/CAD9bWYwtxjinYmeNWZvBdCdQB5zAa3je1bwMjUhmzEjzF0Q_bg%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 

Re: List validator

2023-02-28 Thread Geo Jacob
Larry,

It seems like request data field name don't have underscore. It should
be case_status
instead of casestatus

Regards,
Geo


On Tue, Feb 28, 2023 at 2:12 AM Larry Martell 
wrote:

> I have this defined in my serializer:
>
> case_status = serializers.ListField(
> child=serializers.CharField(
> allow_blank=True,
> max_length=512,
> allow_null=True,
> required=False,
> default="''",
> ),
> source='casestatus',
> required=False,
> allow_empty=True,
> )
>
> When this data is received:
>
> (Pdb) request.data
> 
>
> The casestatus field is not picked up:
>
> (Pdb) serializer.validated_data
> OrderedDict([('patientid', 0), ('pk', 0), ('patientname', "''"), ('dobstart', 
> "''"), ('dobend', "''"), ('scanstart', "''"), ('scanend', "''"), 
> ('workitemstr', "''"), ('institutionid', 0), ('page_size', 10), 
> ('sortByDateCreated', 'true')])
>
> Can anyone see what I am doing wrong here?
>
> --
> 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/CACwCsY6-wEO-vVDn_mhb8t0-w2C5vXyw-08EeuUeiAPmMK_oqw%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/CAFkw%3Dc%3DZ6MaF8CXvRmx08cUx-tTC8LjhJ7dX-xPfWdQT9DOVGQ%40mail.gmail.com.


Re: Need way of authentication with google without using an allauth packages

2023-02-28 Thread Jeman Kumar
https://python-social-auth.readthedocs.io/en/latest/configuration/django.html

On Tue, 28 Feb, 2023, 12:50 pm MaheshKumar,  wrote:

> I need how to create an google authentication without using the django
> -allauth packages.
>
>
> Please give me an idea to create an flow of authentication with google in
> django
>
> --
> 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/cafb233e-2689-4613-adf0-7751bcbdce94n%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/CALmE1Ttd1NJEvAR2x6L2%3DtyRGpN5oSfUqSxpbFtM8jMT9ZhYMg%40mail.gmail.com.


Re: Need way of authentication with google without using an allauth packages

2023-02-28 Thread Vineet Kothari
https://realpython.com/flask-google-login/

Try this one to get an overall idea the concept is same for google.


On Tue, 28 Feb 2023, 7:34 pm Dev Femi Badmus, 
wrote:

> google cloud auth or account auth, which one??
>
> On Tue, Feb 28, 2023 at 8:21 AM MaheshKumar  wrote:
>
>> I need how to create an google authentication without using the django
>> -allauth packages.
>>
>>
>> Please give me an idea to create an flow of authentication with google in
>> django
>>
>> --
>> 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/cafb233e-2689-4613-adf0-7751bcbdce94n%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/CAD9bWYxc6OPqD5qoUz-vWAU7rPFfwfYU9RdLCD%3DcnnFgpXzCXA%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/CAAcanssGdwAOQHsONeF4XmMsmCOyt2u%2Br9EKZot-LypsbCqZkw%40mail.gmail.com.


Re: Need way of authentication with google without using an allauth packages

2023-02-28 Thread Dev Femi Badmus
google cloud auth or account auth, which one??

On Tue, Feb 28, 2023 at 8:21 AM MaheshKumar  wrote:

> I need how to create an google authentication without using the django
> -allauth packages.
>
>
> Please give me an idea to create an flow of authentication with google in
> django
>
> --
> 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/cafb233e-2689-4613-adf0-7751bcbdce94n%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/CAD9bWYxc6OPqD5qoUz-vWAU7rPFfwfYU9RdLCD%3DcnnFgpXzCXA%40mail.gmail.com.


Re: How to retrieve the latest object added (new one) in Django models and display it in the template?

2023-02-28 Thread Dev Femi Badmus
all_action=ActionGame.objects.all()
my_action = []
for action in all_action:
my_action.append(action)
last_action = my_action[-1]


On Tue, Feb 28, 2023 at 1:05 PM Andréas Kühne 
wrote:

> Se comments below.
>
>
> Den fre 24 feb. 2023 kl 12:14 skrev Byansi Samuel <
> samuelbyans...@gmail.com>:
>
>> Hey everyone, l got a problem. Am trying to retrieve a single latest
>> object added everytime, and display it in the template.
>> Below is my codes but;
>>
>> Help me figure it out the source of the problem in these different
>> instances below 
>>
>> ___ issue number 1___
>>
>> #Action/models.py
>> class ActionGame(models.Model):
>> name=models.Charfield()
>> published=models.DateTimeField()
>>
>> #Action/views.py
>> from Action.models import ActionGame
>>
>> def action (request):
>> latest_action=ActionGame.objects.filter(published=published).
>> latest()
>> Context={ 'latest_action': latest_action }
>> return
>>
>> But it returns *error* :
>> name 'published' is not defined
>>
>
> You haven't defined what the value of published is. If you want to get the
> last created one the query should be:
> latest_action=ActionGame.objects.latest("published") - that would give you
> the last published item. Another way would be:
> latest_action=ActionGame.objects.order_by("published").last()
>
>
>>  issue number 2
>>
>> #Action/models.py
>> class ActionGame(models.Model):
>> name=models.Charfield()
>> published=models.DateTimeField()
>> class Meta:
>>   get_latest_by='published'
>>
>> #Action/views.py
>> 
>> latest_action=ActionGame.objects. latest()
>> ...
>>
>> #but it returns *error* :
>> 'ActionGame' object is not iterable
>>
>> Even if I try this:
>> 
>> latest_action=ActionGame.objects. latest('published')
>> ...
>>
>> #it returns the Same error:
>> 'ActionGame' object is not iterable
>>
>> But this second issue, the error is referred in #action.html
>>
>> {% for x in latest _action %}
>> {{ x.game_name }}
>> {% endfor %}
>>
>>
> So the latest_action variable that you have sent to the template is an
> instance of ActionGame - and not a list or anything. You can only access
> variables in the ActionGame class. For example:
>
>  {{ lastest_action.name }}
>
> would print out the value of the name of the ActionGame instance.
>
> Please l need your assistance.
>>
>> I'm Samuel,
>> Thanks
>>
>> --
>> 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/CAGQoQ3wMUno6hLAO-1FtN0Nn7VtkCn4qf-O4U%3DpeJ4JzY%2B%3DcAQ%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/CAK4qSCeBCST7o-5WZx%2BmhGO2yH-Msdse%3DKusk9UOyW8XZBXRBw%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/CAD9bWYwtxjinYmeNWZvBdCdQB5zAa3je1bwMjUhmzEjzF0Q_bg%40mail.gmail.com.


Re: How to retrieve the latest object added (new one) in Django models and display it in the template?

2023-02-28 Thread Andréas Kühne
Se comments below.


Den fre 24 feb. 2023 kl 12:14 skrev Byansi Samuel :

> Hey everyone, l got a problem. Am trying to retrieve a single latest
> object added everytime, and display it in the template.
> Below is my codes but;
>
> Help me figure it out the source of the problem in these different
> instances below 
>
> ___ issue number 1___
>
> #Action/models.py
> class ActionGame(models.Model):
> name=models.Charfield()
> published=models.DateTimeField()
>
> #Action/views.py
> from Action.models import ActionGame
>
> def action (request):
> latest_action=ActionGame.objects.filter(published=published).
> latest()
> Context={ 'latest_action': latest_action }
> return
>
> But it returns *error* :
> name 'published' is not defined
>

You haven't defined what the value of published is. If you want to get the
last created one the query should be:
latest_action=ActionGame.objects.latest("published") - that would give you
the last published item. Another way would be:
latest_action=ActionGame.objects.order_by("published").last()


>  issue number 2
>
> #Action/models.py
> class ActionGame(models.Model):
> name=models.Charfield()
> published=models.DateTimeField()
> class Meta:
>   get_latest_by='published'
>
> #Action/views.py
> 
> latest_action=ActionGame.objects. latest()
> ...
>
> #but it returns *error* :
> 'ActionGame' object is not iterable
>
> Even if I try this:
> 
> latest_action=ActionGame.objects. latest('published')
> ...
>
> #it returns the Same error:
> 'ActionGame' object is not iterable
>
> But this second issue, the error is referred in #action.html
>
> {% for x in latest _action %}
> {{ x.game_name }}
> {% endfor %}
>
>
So the latest_action variable that you have sent to the template is an
instance of ActionGame - and not a list or anything. You can only access
variables in the ActionGame class. For example:

 {{ lastest_action.name }}

would print out the value of the name of the ActionGame instance.

Please l need your assistance.
>
> I'm Samuel,
> Thanks
>
> --
> 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/CAGQoQ3wMUno6hLAO-1FtN0Nn7VtkCn4qf-O4U%3DpeJ4JzY%2B%3DcAQ%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/CAK4qSCeBCST7o-5WZx%2BmhGO2yH-Msdse%3DKusk9UOyW8XZBXRBw%40mail.gmail.com.


Re: How can I serve an Angular app from root?

2023-02-28 Thread Andréas Kühne
Hi,

You shouldn't be serving your angular application that way. Running it in
development, you run it and serve it from the "ng serve" command.
Running in production, you need to have a webserver in front of your
application any way, and should serve the angular files from the webserver.

Med vänliga hälsningar,

Andréas


Den sön 26 feb. 2023 kl 21:22 skrev Zayd Krunz :

> Hello,
> I have a prebuilt Angular app, which is basically just static files. How
> can I serve it from the root project? If I set STATIC_URL to "/", I get the
> following:
>
> django.core.exceptions.ImproperlyConfigured: runserver can't serve media
> if MEDIA_URL is within STATIC_URL.
>
> --
> 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/60f7e50e-7900-46f1-a91e-67038ea91e30n%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/CAK4qSCdKVjmtThYiKdQnRTYe9PEP-5Smee2LWfqUq7_edLC81Q%40mail.gmail.com.