czue / django-wedding-website

A django-powered wedding website and guest-management system
Other
458 stars 273 forks source link

Great Project, Django & Python help, if possible #70

Closed m1ckyb closed 6 months ago

m1ckyb commented 6 months ago

Hi,

I would like to say a big thanks for this, over the past few months i have tinkered with the code to suit my needs, but i am no expert when it comes to Python or Django and have winged it with most of the changes in the code, and that is where my Google search skills come to a end.

In the invitation.html file i have added a checkbox for if the guest requires a bus to/from the venue, which does show up in the page, but i have no idea on how to save the details into the database and to show the checkbox if the guest reloads the invitation page

guests/templates/guests/invitation.html

            <div class="form-group">
                <label for="{{ bus_req }}" class="col-sm-3 control-label">... Require bus?</label>
                <input type='checkbox' name='bus_req' value="{{ bus_req }}">{{ bus_req }}</input>      
            </div>    

guests/models.py

class Guest(models.Model):
    (other code)
    req_bus = models.BooleanField(default=False)

guests/migrations/0022_req_bus.py

# -*- coding: utf-8 -*-
# Generated by Django 1.9 on 2016-01-18 19:29
from __future__ import unicode_literals

from django.db import migrations, models

class Migration(migrations.Migration):

    dependencies = [
        ('guests', '0021_phone_party'),
    ]

    operations = [
        migrations.AddField(
            model_name='guest',
            name='req_bus',
            field=models.BooleanField(default=False),
        ),
    ]

Any help would be greatly appreciated,

Thanks

Michael

czue commented 6 months ago

Thanks! After adding the field and running the migration, you should be able to save it by adding req_bus to the guest object here:

https://github.com/czue/django-wedding-website/blob/master/guests/views.py#L74-L81

You will also have to parse the form value here:

https://github.com/czue/django-wedding-website/blob/master/guests/views.py#L99-L109

Note: I have no recollection of why I did form parsing that way instead of using Django forms. But it should be relatively easy to adapt by copy/pasting what's already there.

m1ckyb commented 6 months ago

Thanks for your help, after many hours of attempting to figure it out, i have up on using 'checkbox' and just copied the code for the meal radio buttons, and got it working..

Many Thanks

Michael

czue commented 6 months ago

glad you got it working!