i have a following problem...
I create "event" in my project but i can not invite friends to this "event". I don't get how to identify the "event" correctly to make a invite request to friend.
models.py
class Event(models.Model):
title = models.CharField(max_length=200, blank=False, null=False)
creator = models.ForeignKey(
Profile, on_delete=models.CASCADE, related_name='creator')
participators = models.ManyToManyField(Profile, blank=True)
description = models.TextField(blank=True)
start = models.CharField(max_length=5)
finish = models.CharField(max_length=5)
event_date = models.CharField(max_length=50)
timestamp = models.DateTimeField(auto_now_add=True)
class Meta:
ordering = ('-timestamp', )
def __str__(self):
return f"Event: {self.title} by {self.creator}. \
Date: {self.event_date}. From:{self.start} to {self.finish}"
def get_sum_participators(self):
return self.participators.count()
class EventInviteRequest(models.Model):
from_event = models.ForeignKey(Event, on_delete=models.CASCADE,
related_name='from_event', null=True)
to_profile = models.ForeignKey(Profile, on_delete=models.CASCADE,
related_name='to_profile', null=True)
timestamp = models.DateTimeField(auto_now_add=True)
def __str__(self):
return f"From {self.from_event} to {self.to_profile}"
This is a function i'm trying to use, but it sends request to 'event' creator.
def from_event_to_user_invite_request(request, id):
event = Event.objects.get(id=id)
to_profile = Profile.objects.get(id=id)
event_invite, created = EventInviteRequest.objects.get_or_create(
request, from_event=event, to_profile=to_profile)
return redirect('events:event_page', event.id)
Could you give me some tips how to fix the problem
Thank you
Update
Now it's work for me
def from_event_to_user_invite_request(request, event_id, profile_id):
profile = Profile.objects.get(id=profile_id)
event = Event.objects.get(id=event_id)
event_invite, created = EventInviteRequest.objects.get_or_create(
request, from_event=event, to_profile=profile)
return redirect('events:event_page', event.id)
CodePudding user response:
The easiest way is to pass the profile_id and the event_id,do not forget to change your url for this to work.
def from_event_to_user_invite_request(request,event_id,profile_id):
event_invite, created = EventInviteRequest.objects.get_or_create(from_event_id=event_id, to_profile_id=profile_id)
return redirect('events:event_page',event_id)