Re: How 2 access the Primary model's ID in the Foreign model??

2018-12-31 Thread Peter of the Norse
Also song.album_id will work as well, and faster too. Sent from my iPad > On Dec 4, 2018, at 3:43 PM, Mike Dewhirst wrote: > >> On 5/12/2018 7:07 AM, Sourajit Mohanty wrote: >> I have 2 model classes Album and Songs(where Song is the Foreign key) >> I want to access the Albums ID in the Songs c

Re: How to access using foreing key

2020-12-13 Thread Peter of the Norse
If you are looking for all of the Restaurants with a 5.0 rating, it looks like Restaurant.objects.filter(rating_restaurant__rating = 5.0) If you are looking for Restaurants with an average rating of 5.0, that’s a bit trickier. from django.db.models import Avg Restaurant.objects.annotate(avg_rat

Re: ForeignKey with different queryset from manager

2021-01-10 Thread Peter of the Norse
This is an interesting question. Thank you for asking it. I wasn’t able to find exactly what you are asking for. The closest I could find was https://docs.djangoproject.com/en/2.2/topics/db/queries/#using-a-custom-reverse-manager

Re: How to securely store passwords used in backend code

2021-01-10 Thread Peter of the Norse
I use multiple settings.py files to do this. Specifically, in my main one, I have what I consider the only acceptable instance of import *. import os if (os.getenv('PRODUCTION')): from .prod_settings import * else: from .dev_settings import * While dev_settings.py is in my repo, prod_se

Re: QuerySet performance on large datasets

2021-02-12 Thread Peter of the Norse
bool(qs) is recommended when the queryset has already been run. If you do something like val = qs.earliest(some_property) if bool(qs) else None then there isn’t a performance gain because it still has to run qs.exists() to even see if there is a value. Later things like that will be cach

Re: What values is expected for CSRF_COOKIE_PATH ?

2021-03-08 Thread Peter of the Norse
Some sites have Django installed in a sub-path of their site, e.g. http://mydomain.com/django/. In that case, you can set it to “/django-project/“ or “/“. Since the default is / you don’t need to do anything. If you have two separate Django installations on one site, then you need to change

Re: QuerySet performance on large datasets

2021-04-11 Thread Peter of the Norse
taff", "auth_user"."is_active", "auth_user"."date_joined" FROM "auth_user"; args=() (0.000) SELECT "auth_user"."id", "auth_user"."password", "auth_user"."last_login", "auth_user&q

Re: Question about models. test

2021-05-02 Thread Peter of the Norse
This kind of script can be dangerous. It’s possible for malicious websites to create a page that can use up too many resources or otherwise act strangely. URLValidator

Re: Django 3.1 Makemigrations fails with FilePathField but succeeds with CharField

2021-06-22 Thread Peter of the Norse
I think you might be better off using https://docs.djangoproject.com/en/3.2/topics/migrations/#squashing-migrations than having it recreate all of them. > On Mar 18, 2021, at 8:28 AM, Olivier wrote: > > Hello, >

<    1   2