Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 962091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:27:01+00:00 2026-05-16T01:27:01+00:00

I am working on a membership application. I would like to make a membership

  • 0

I am working on a membership application. I would like to make a membership reminder. (member during a period of time which is not member for another period of time).

Currently, I am using set for making this calculation. See the code below.

class Member(models.Model):
     ...

class Membership(models.Model):
    member = models.ForeignKey(Member, verbose_name=_("Member"))
    start_date = models.DateField(_("Start date"))
    end_date = models.DateField(_("End date"))

x = Member.objects.filter(Q(membership__start_date__lte=dt1) & Q(membership__end_date__gte=dt1))
y = Member.objects.filter(Q(membership__start_date__lte=dt2) & Q(membership__end_date__gte=dt2))
result = set(x) - set(y)

I would like to know of I can do it only by using the django ORM (filter, exclude, annotate, distinct …)?

Thanks in advance for your help

UPDATE

In fact, my model is a bit more complex. I also have newspaper foreign key.

class Member(models.Model):
     ...

class Newspaper(models.Model):
     ...

class Membership(models.Model):
    member = models.ForeignKey(Member, verbose_name=_("Member"))
    start_date = models.DateField(_("Start date"))
    end_date = models.DateField(_("End date"))
    newspaper = models.ForeignKey(Newspaper)

I want to have the reminder for a given newspaper. In this case, the working query is

sin = models.Membership.objects.filter(start_date__lte=dt1,
                                               end_date__gte=dt1,
                                               newspaper__id=2)

sout = models.Membership.objects.filter(start_date__lte=dt2,
                                          end_date__gte=dt2,
                                          newspaper__id=2)
result = models.Member.objects.filter(membership__in=sin).exclude(membership__in=sout)

I think that this a more verbose version of the answer given Ghislain Leveque which is also working well for me.

Thanks to S.Lott and KillianDS for very valuable answers and sorry for not so clear question 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T01:27:01+00:00Added an answer on May 16, 2026 at 1:27 am

    You should try :

    result = Member.objects.\
        filter(
            membership__start_date__lte = dt1,
            membership__end_date__gte=dt1).\
        exclude(
            pk__in = \
                Member.objects.filter(
                    membership__start_date__lte = dt2,
                    membership__end_date__gte = dt2).\
        values_list('pk')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on a membership system for my web application, which is based
I am currently working on an ASP.NET MVC2 application and would just like to
I'm working on creating a membership-based web application. In order to become a member,
I'm currently working with an Asp.NET web application which involves a lot of stored
I'm working on an Asp.Net 4.0 web application which is using the Membership and
I'm working on a custom implementation of ASP.NET membership, which uses my own database
I am currently designing a Membership/Profile scheme for a new project I am working
I have a web application which uses membership and profiles. I successfully used the
I am developing an MVC 4 application. I am working on the membership authentication
For a Django application that I'm working on, I wanted to allow group membership

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.