Using Forms in Django - Adding people to a specific date
<p>I've searched the site, which has been extremely helpful with other issues being that I'm new to Django.  I can't seem to figure out how to add people to a date/event.  </p>

<p><a href="http://i.stack.imgur.com/g2OC2.png" rel="nofollow">Models</a></p>

<pre><code>class PeopleList(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
phone_number = models.CharField(null='True', max_length=12)
MALE = 'M'
FEMALE = 'F'
GENDER_CHOICES = (
    (MALE, 'Male'),
    (FEMALE, 'Female'),
    )
gender = models.CharField(
    max_length=6,
    choices=GENDER_CHOICES,
    )

def __str__(self):
    return "%s %s" % (self.first_name, self.last_name)


class Date(models.Model):
HARDWARE_SHOW = 'Hardware Show'
METAL_SHOW = 'Metal Show'
MEETING_NAME_CHOICES = (
    (HARDWARE_SHOW, 'Hardware Show'),
    (METAL_SHOW, 'Metal Show'),
    )
meeting_name = models.CharField(
    max_length=50,
    choices=MEETING_NAME_CHOICES,
    )
date_of_meeting = models.DateField()


def __str__(self):
    return "%s - %s" % (self.meeting_name, self.date_of_meeting)

class MeetingAttendance(models.Model):
meeting_date = models.ForeignKey('Date', on_delete=models.CASCADE)
person = models.ForeignKey('PeopleList', on_delete=models.CASCADE)
attended = models.BooleanField()


def __str__(self):
    return "%s - %s" % (self.person, self.meeting_date)
</code></pre>

<p>My models are a PeopleList (which is people we'd invite to each event).  The form for this works great and I can add people to this growing list.  The Date model shows Dates that we will have events.  The form for this works well since I can continue to add more dates of events.  And the MeetingAttendance is the model where I'd like to add people to a date so I can see who went to the event, but when I create a form for it, it isn't coming out how I'd like.  It gives me dropdowns since I'm using Foreign Key, but I just want everyone's names (non-editable), the meeting date (non-editable), and then a checkbox to click off if they came or not.</p>

<p>What I'm trying to do is be able to open up an event date (and I don't believe I'm routing the date to url correctly, but thats a separate issue), see a list of everyone on our PeopleList and then check-off if they attended to event or not.  From there, on the same page (further down) I'd like to show the actual attendance to that specific event (PeopleList who attended that specific date).  I kept changing around my detail view, and now it's a bit of a mess.</p>

<p><a href="http://i.stack.imgur.com/p7L1x.png" rel="nofollow">Event Detail View</a></p>

<pre><code>def meeting_detail(request, pk):
attended = MeetingAttendance.objects.filter(meeting_date__pk=pk, attended='True')
people = PeopleList.objects.all().order_by('last_name')
if request.method == "POST":
    form = MeetingFormSet(request.POST)
    if form.is_valid():
        formset = form.save(commit=False)
        formset.save()
        return redirect('meeting_detail', pk=pk)
else:
    form = MeetingFormSet()
context = {
    'form': form,
    'attended': attended,
    'people': people,
}   
return render(request, 'statistics/meeting_detail.html', context)
</code></pre>

<p>URLs</p>

<pre><code>urlpatterns = [
url(r'^$', views.date_list, name='date_list'),
url(r'^meeting/(?P&lt;pk&gt;\d+)/$', views.meeting_detail, name='meeting_detail'),
url(r'^date/new/$', views.date_new, name='date_new'),
</code></pre>

<p>Forms:</p>

<pre><code>class DateForm(forms.ModelForm):

class Meta:
    model = Date
    fields = ('meeting_name', 'date_of_meeting',)

class MeetingForm(forms.ModelForm):

class Meta:
    model = PeopleList
    fields = ('first_name', 'last_name', 'phone_number', 'gender',)
</code></pre>

<p>Any ideas on the easiest way to put this together based on what I currently have?</p>

<p>Thank you!</p>

<p>If i understand you correctly, you want to sort by date and check people on the list based on the date... you can use django order by to do that( query based on date and fetch people that matches, let me know if you need practical proof so i can add it.</p>

python django