skip to Main Content

Postgresql – Django prefetch_related on ForeignKey relation

I have this database setup: class Profile(AbstractBaseUser, PermissionsMixin): email = models.CharField(max_length=30, null=True, unique=True) date_created = models.DateTimeField(auto_now=True) ... class SubProfile(models.Model): profile = models.OneToOneField(Profile, on_delete=models.CASCADE) display_name = models.CharField(max_length=25) ... class SubProfilePost(models.Model): profile = models.ForeignKey(Profile, related_name='sub_profile_postings', on_delete=models.CASCADE) title = models.CharField(max_length=20, null=False) looking_for_date =…

VIEW QUESTION

Group multiple events for ID in postgreSQL data

I'm trying to select pairs of events from my data. I have a data that looks like this: create table test(id,status,created)as values (1, 'on','2024-09-01'::date) ,(2, 'on','2024-09-02'::date) ,(1,'off','2024-09-03'::date) ,(1, 'on','2024-09-04'::date) ,(2,'off','2024-09-05'::date) ,(3, 'on','2024-09-06'::date) ,(1,'off','2024-09-07'::date) ,(4,'off','2024-09-08'::date); I would like to have data…

VIEW QUESTION
Back To Top
Search