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 7933069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:12:54+00:00 2026-06-03T21:12:54+00:00

I have a model for an event simply which has start_date and end_date and

  • 0

I have a model for an event simply which has start_date and end_date and the critical part is date range must be unique.

For that reason, I wrote query like(Q) filters which checks date range is unique or not.
Anyway, my problem is at in view part; I need to create an Event object when user comes to event adding page with initial dates,(User can change it later with respect to date range uniqueness)

How can I decide(filter) to which days not include in any Event object ?
or If there any available date in this month ? with django filters or some smart approach…

#model:
class Event(models.Model):

    user = models.ForeignKey(User)
    start_date = models.DateTimeField()
    end_date = models.DateTimeField()
    status = models.IntegerField(default=0)

    def save(self, *args, **kwargs):
        try:
            Event.objects.get(
                Q(user=self.user, status=1),
                Q(start_date__range=(self.start_date, self.end_date))
                |Q(end_date__range=(self.start_date, self.end_date))
                |Q(start_date__lte=self.start_date, end_date__gte=self.end_date)
            )
            raise IntegrityError("Error message")
        except Event.DoesNotExist:
            super(Event,self).save(*args,**kwargs)

In my view: there is one function which is for creating an Event object with initial dates and redirect to url, for updating/editing event details.

#view:
try:
    event = Event.objects.create(user=request.user,
                                 start_date=datetime.date.today(), 
                                 end_date=datetime.date.today())
except IntegrityError, e:
    return HttpResponse(e)

ps: if there is more smarter way of doing this with some different design approach , I would be happy to hear.

  • 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-06-03T21:12:57+00:00Added an answer on June 3, 2026 at 9:12 pm

    Not to the heart of your question, but note that you don’t cover the MultipleObjectsReturned case here:

        try:
            Event.objects.get(
                Q(user=self.user, status=1),
                Q(start_date__range=(self.start_date, self.end_date))
                |Q(end_date__range(self.start_date, self.end_date))
                |Q(start_date__lte=self.start_date, end_date__gte=self.end_date)
            )
            raise IntegrityError("Error message")
        except Event.DoesNotExist:
            super(Event,self).save(*args,**kwargs)
    

    I think it would be better

        if Event.objects.filter(
            Q(user=self.user, status=1),
            Q(start_date__range=(self.start_date, self.end_date))
            | Q(end_date__range(self.start_date, self.end_date))
            | Q(start_date__lte=self.start_date, end_date__gte=self.end_date)
        ):
            raise IntegrityError("Error message")
        else:
            super(Event,self).save(*args,**kwargs)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model of events that has various information such as date, location,
Does jquery/javascript have any event model that you can attach to your objects? Basically
I have a model that looks like this: class Invite(models.Model): user = models.ForeignKey(User) event
I have two models: class Actor(models.Model): name = models.CharField(max_length=30, unique = True) event =
I have models similar to the following: class Band(models.Model): name = models.CharField(unique=True) class Event(models.Model):
We have a model EventSession which has several subtypes via STI, including NetworkingEventSession and
I have model: [XmlRoot(ElementName = event, IsNullable=true)] public class Event { public int id
I have a parent entity in my model Event. And two child entities: Birthday,
I have this model var Item = Backbone.Model.extend({ url: 'http://localhost/InterprisePOS/Product/loaditembycategory/Event Materials' }); var onSuccess
I have a Django model with separate Datefield and Timefield for an event. Is

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.