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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:07:31+00:00 2026-06-04T08:07:31+00:00

I have the following model: from django.db import models import datetime class Club(models.Model): establishment

  • 0

I have the following model:

from django.db import models
import datetime

class Club(models.Model):
    establishment = models.CharField(max_length=200)
    address = models.CharField(max_length=200)
    def __unicode__(self):
        return self.establishment

class Day(models.Model):
    club = models.ForeignKey(Club)
    day = models.DateField('day')
    def __unicode__(self):
        return unicode(self.day)

class Court(models.Model):
    club = models.ForeignKey(Club)
    day = models.ForeignKey(Day)
    court = models.IntegerField(max_length=200)
    def __unicode__(self):
        return unicode(self.court)

class Slot(models.Model):
    club = models.ForeignKey(Club)
    day = models.ForeignKey(Day)
    court = models.ForeignKey(Court)
    slot = models.TimeField('slot')
    reservation = models.CharField(max_length=200)
    def __unicode__(self):
        return unicode(self.slot)

In the Slot model, each “slot” can either be “open” or have any other value (usually an email) in the “reservation” field. What I am trying to do: given a club_id that’s passed into a function, display all the fields in “slot” that have a reservation value of “open” and a “day” that is equal to today…and then pass this into the template.

def avail_times(request, club_id):
    p = get_object_or_404(Slot,pk=club_id)
    return render_to_response('reserve/templates/avail_times.html', {'times':p})

I’m not able to do it with the current view/template I have; it only returns a time. How do I reference “day” and “club” within the view (given the club_id) and then display the above in the template?

  • 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-04T08:07:32+00:00Added an answer on June 4, 2026 at 8:07 am

    For a start, that query doesn’t do what you say you want. To get all of today’s open slots for a given club, you’d need something like this:

    open_slots = Slot.objects.filter(club_id=club_id, day__day=datetime.date.today(),
                                     reservation='open')
    

    Now in your template you can iterate through open_slots, and show the slot time (you should choose a better field name here) for each.

    By the way, I don’t understand the point of the Day model, or at least why you’ve got a FK from Court to Day. Courts are the same whatever day it is, and the only thing that should be related to Day is Slot. Similarly, Day doesn’t need a FK to Club (it’s still Monday whichever club you’re at). In fact you could remove the Day model altogether and just use a DateField directly on Slot.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following model: from django.db import models class State(models.Model): name = models.CharField(max_length=30)
I have the following model. from django.db import models class Client(models.Model): postcode = models.CharField(max_length=10)
Suppose I have the following Event model: from django.db import models import datetime class
I have the following model: class User: name = models.CharField( max_length = 200 )
I have following setup. from django.db import models from django.contrib.auth.models import User class Event(models.Model):
Let's assume we have following models: from django.db import models class Foo(models.Model): name =
I have the following: from django.contrib.auth.models import User class ClientDetails(models.Model): created_by = models.ForeignKey(User) ...
I have the following multi-table inheritance situation: from django.db import Models class Partner(models.Model): #
I have the following model and instance: class Bashable(models.Model): name = models.CharField(max_length=100) >>> foo
I have the following python code: from django.db import models from datetime import datetime

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.