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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:37:57+00:00 2026-06-06T19:37:57+00:00

I’m new to Django and just trying to submit a form using ModelForms to

  • 0

I’m new to Django and just trying to submit a form using ModelForms to create a new event and save it to the database.

I am trying to insert rows into three tables: Location, Event (which has a location_id FK), and EventSchedule (which as an event_id FK).

Here is the method that saves the forms. When it is called, no errors are returned, yet the new rows are not inserted into the database.:

addNewEvent() (in views.py)

def addNewEvent(self, event_form, location_form, event_sched_form, latitude, longitude):

    new_event = event_form.save(commit=False)
    new_location = location_form.save(commit=False)
    new_event_sched = event_sched_form.save(commit=False)
    # set any necessary values and save forms
    new_location.latitude = latitude
    new_location.longitude = longitude
    new_location.save()
    new_event.flagged = False
    new_event.location = new_location
    new_event.save()
    new_event_sched.event = new_event
    new_event_sched.save()

models.py

class Location(models.Model):
    name = models.CharField(max_length=200)
    #address = models.CharField(max_length=200)
    city = models.CharField(max_length=200)
    state_code = models.CharField(max_length=100)
    zip = models.CharField(max_length=100, blank=True)
    country = models.CharField(max_length=100)
    latitude = models.DecimalField(max_digits=9, decimal_places=6)
    longitude = models.DecimalField(max_digits=9, decimal_places=6)
    class Meta:
        db_table = 'location'

class Event(models.Model):
    CATEGORIES = (
        ('KID', 'Kids'),
        ('FAM', 'Family'),
        ('NIT', 'Nightlife'),
        ('OUT', 'Outdoors'),
        ('ART', 'Arts'),
        ('MSC', 'Music'),
        ('SPT', 'Sports'),
        ('SAL', 'Sale'),
        ('EDU', 'Educational'),
        ('POL', 'Political'),
        ('FOD', 'Food'),
        ('OTH', 'Other')
    )
    location = models.ForeignKey(Location)
    name = models.CharField(max_length=200)
    description = models.CharField(max_length=200)
    category = models.CharField(max_length=20, choices=CATEGORIES)
    age_req = models.IntegerField(null=True)
    cost_per_person = models.DecimalField(max_digits=5, decimal_places=2, null=True)
    flagged = models.BooleanField()
    users = models.ManyToManyField(User, through='UserEvent')
    class Meta:
        db_table = 'event'

class EventSchedule(models.Model):
    event = models.ForeignKey(Event)
    start_date_time = models.DateTimeField()
    end_date_time = models.DateTimeField()
    class Meta:
        db_table = 'event_schedule'

forms.py

from django.forms import ModelForm, forms
from models import Event, Location, EventSchedule

class EventForm(ModelForm):
    class Meta:
        model = Event
        fields = ('name','description','category','age_req','cost_per_person')

class LocationForm(ModelForm):
    class Meta:
        model = Location
        fields = ('name','city','state_code','zip','country')

class EventScheduleForm(ModelForm):
    class Meta:
        model = EventSchedule
        fields = ('start_date_time', 'end_date_time')

Any help is much appreciated.

Thank you,

Peter

EDIT:

I can’t even save a Model, let alone a ModelForm (even though I am doing it successfully in other places). I added the following code to associate a user with an event. No errors, yet it doesn’t add a row to the database:

new_user_event = UserEvent(user=user,
                                event=new_event,
                                datetime_created=datetime.datetime.now())
new_user_event.save()

Any ideas?

EDIT 2:

Screenshot of new_user_event: https://i.stack.imgur.com/mHnmR.jpg

EDIT 3:

This is how I’m instantiating the ModelForms:

event_form = EventForm(request.POST or None)
location_form = LocationForm(request.POST or None)
event_sched_form = EventScheduleForm(request.POST or None)
  • 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-06T19:37:58+00:00Added an answer on June 6, 2026 at 7:37 pm

    Wow, I am such an idiot. I was deleting the rows in the tables before I could actually display the events due to some code that populated the database with dummy data.

    Can I delete this question or should it live on as a testament to my stupidity?

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have just tried to save a simple *.rtf file with some websites and
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:

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.