django equivalent to sqlalchemy's sessionmaker
<p>I'm new to Django 1.9 (fairly new to flask, as well), and am trying to populate my models.py much in the same way that sqlite sessionmaker does it. </p>

<p>this is a snip of my models.py:</p>

<pre><code>@python_2_unicode_compatible
class Location(models.Model):
def __str__(self):
    return self.location_text

location_text = models.CharField(max_length=200)
travel_date = models.DateTimeField('date traveled')


@python_2_unicode_compatible
class Countries(models.Model):
    def __str__(self):
        return self.capitals

    location = models.ForeignKey(Location, on_delete=models.CASCADE)
    capitals = models.CharField(max_length=200)
</code></pre>

<p>With flask and sqlalchemy I'd create a new file and be able to do something like this:</p>

<pre><code>from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from this_app.models import Location, Countries

engine = create_engine("the db")
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()

loc1 = Location(location_text = "Indonesia")
session.add(loc1)
session.commit()

cap = Countries(
    capitals="Jakarta",
    location=loc1
    )
session.add(cap)
session.commit()
</code></pre>

<p>How is this done with django's orm?</p>

<pre><code>loc1 = Location.objects.create(location_text="Indonesia")
cap = Countries.objects.create(capitals="Jakarta", location=loc1)
</code></pre>

<p>That's all.</p>

python django sqlalchemy