[Fixed]-How do I create a wide-format data entry form if data is stored in long form in django

1👍

Building a ManyToMany relationship with these models will not break your existing code nor will it make any changes to the database. In fact you already have a ManyToMany, you just have to mark it as such.

class species(models.Model):
   name = models.CharField(max_length=100)
   species_locations = models.ManyToManyField(Locations,through='Occurrences')

When you run the migration you will note that it doesn’t actually make any changes to the database.

Additionally, you have an error in this model.

class occurrences(models.Model):
   species = models.ForeignKey(location)
   location = models.ForeignKey(location)

I do believe you intended species to be a foreign key to Species

The second part of the problem is mostly in HTML rendering, the django component to be used is InlineFormSet this allows related models to be edited easily. (you do not need ManyToMany here if the Occcurence model is what’s been edited in the form)

Leave a comment