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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:49:35+00:00 2026-05-31T05:49:35+00:00

Trying to implement an Attending button. It’s simple (or so I thought). A user

  • 0

Trying to implement an “Attending” button. It’s simple (or so I thought). A user with a profile clicks “Attending”, and a checkmark appears. Can’t quite get this to work on the Django/Python side of things. ie: Put that user who clicked ‘Attending’ into the attendee(list) within the Event.

Template:

{% if is_attending %}
     <button class="btn" disabled="disabled">
         <i class="icon-ok-sign"></i> Attending
     </button>
{% else %}
     <form class="left" method="POST" action="/profile/event/{{ event.id }}/">
     {% csrf_token %}
          <input type="hidden" name="profile_id" value="user" />
          <button class="btn">
               Attending
          </button>
     </form>
{% endif %}

Models:

class Event(models.Model):
    created = models.DateTimeField(auto_now_add=True)
    modified = models.DateTimeField(auto_now=True)
    owner = models.ForeignKey(User, null=True, blank=True, on_delete=models.SET_NULL)
    name = models.CharField(max_length=200)
    location = models.CharField(max_length=200)
    start_date = models.DateTimeField(auto_now=False, auto_now_add=False)
    end_date = models.DateTimeField(auto_now=False, auto_now_add=False)
    about = models.TextField(null=True, blank=True)
    attendees = models.ManyToManyField(Profile, null=True, blank=True)

View:

@login_required
def attending_event(request, event_id):
     event = get_object_or_404(Event, id=event_id)
     if request.method == 'POST':
         try:
             id = request.POST.get('profile_id')
             attendee = Profile.objects.get(id=id)
             relationship = Event.objects.create(attendees__user=attendee)
             is_attending = True
        except:
            pass 
        return HttpResponseRedirect('/profile/event/' + event_id + '/')
    else: 
        if not Event.objects.filter(attendees__user=request.user).exists():
            is_attending = False
    data = { 
        'is_attending': is_attending
        }
    return render_to_response('profiles/event.html', data, context_instance=RequestContext(request))

Maybe there’s something I’m missing and can’t see what it is I’m doing wrong. But if anyone could offer some insight/advice about how to go about completing this; I’d really appreciate it.

  • 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-31T05:49:37+00:00Added an answer on May 31, 2026 at 5:49 am

    Just giving you hint, change it according to your needs

    Template:

    {% if is_attending %} 
         <button class="btn"> # this code will executes when is_attending is True
             <i class="icon-ok-sign"></i> Attending
         </button>
    {% else %}
         <form class="left" method="POST" action="/profile/event/{{ event.id }}/"> # Always user reverse urls instead of Hard coded
         {% csrf_token %}
              <input type="hidden" name="profile_id" value="{{profile.id}}" />
              <button class="btn">
                   Attending
              </button>
         </form>
    {% endif %}
    

    View:

    @login_required
    def event_profile(request, event_id)
        event = get_object_or_404(Event, id=event_id)
        if request.method == 'POST':
            try:
                id = request.POST.get('profile_id')
                attendee = Profile.objects.get(id=id)
                relationship = Event.objects.create(attendees__user=attendee, .... ) # set other variable you want
                is_attending = True
        else:
            # check in your event either your profile user is already attending or not? and set is_attending variable according to it
        data = { 
                'is_attending': is_attending,
                 ....
                }
       return render_to_response('my_template.html',
                              data,
                              context_instance=RequestContext(request))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to implement simple error handling without adding buku try / except statements to
I cannot get my code to work! I am trying to implement the quick
Trying to implement AVAudioplayer and get some metering data of the played music, but
I am trying to get a default query to implement upon page load but
Trying to implement a simple print in SL4. I have a DataGrid that I
All I am currently trying implement something along the lines of dim l_stuff as
trying to implement a dialog-box style behaviour using a separate div section with all
Trying to implement a rating system of users and postings. What is the best
Trying to implement a UITableView of names similar to the built-in Contacts iPhone app
Am trying to implement a generic way for reading sections from a config file.

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.