Getting Django Models into SQLite3 DB with VS

I ran into some troubles migrating/configuring my tables for a new app in my Django project.

I’ve been following this excellent tutorial, and ran into a bump I thought needed some clarification/update. As I’m not sure if the guide is up to date with the current version of Django.

Things I searched:
no module named models
manage.py sqlall
django not creating db
models are not being created in sqlite3 Django
sqlite3 not creating table django
No migrations to apply
django sqlite3 unable to create tables
manage.py shell
sqlite3 python package

Do these correlate with what you’re having issues with?
If so this was my solution.

First Install SQLite3 and add it too your Environment Variables -> Path
Install Page — Select: Source Code -> Zip for windows machines
I extracted it to C:/.
Now I have SQLite.exe in my root directory.
This is what the end of my Path looks like:
C:\Program Files\Microsoft\Web Platform Installer\;C:\SQLITE3.EXE\;

Sweet, now we can use SQLite in Powershell.

Configuration of Visual Studio:
Create a new app by right clicking on your Project file.
Then “Add” -> Select “Django App”
In this case my app is named book.

DjangoApp Solution Explorer

Sweet, now we have another Python app.
Go into your settings file and add it to the INSTALLED_APPS tuple.
eg. ‘book’,

Okay, now we’re configured make sure you’re SQLiteDB is properly configured as well.

eg:
‘ENGINE’: ‘django.db.backends.sqlite3’,
‘NAME’: path.join(PROJECT_ROOT, ‘db.sqlite3’),
‘USER’: ”,
‘PASSWORD’: ”,
‘HOST’: ”,
‘PORT’: ”,

Sweet, db all locked and loaded.

Next we’ll create a model.
Following along with the tutorial.
We go into: book -> models.py and create our models.
Eg:
class Publisher(models.Model):
name = models.CharField(max_length=30)
address = models.CharField(max_length=50)
city = models.CharField(max_length=60)
state_province = models.CharField(max_length=30)
country = models.CharField(max_length=50)
website = models.URLField()

Sweet. Model made. Let’s get it into our SQLite DB.

Alright now in DjangoProject1Hack (Where ‘ls’ will show db.sqlite3 among others)
We’ll be doing the migration.

1. Validate:
Run- C:\Python27\python.exe manage.py validate
2. makemigrations
Run- C:\Python27\python.exe manage.py makemigrations
Output:
Migrations for ‘book’:
0001_initial.py:
– Create model Author
– Create model Book
– Create model Publisher
– Add field publisher to book
3. Sync (This just makes sure we add what’s missing)
Run- C:\Python27\python.exe manage.py syncdb
Output:
Operations to perform:
Apply all migrations: book
Running migrations:
Applying book.0001_initial… OK

Sweeeeeeet!

Okay now we manage the db:
Run- C:\Python27\python.exe manage.py shell

Sample workflow in Shell:

>>> from book.models import Publisher
>>> p1 = Publisher(name=’Apress’, address=’2855 Telegraph ave’, city=’berkely’, state_province=’CA’, country=’USA’, website=
‘http://www.apress.com/’)
>>> p1.save()
>>> p2 = Publisher(name=”o’reilly”, address=’10 Fawcett St.’, city=’Cambridge’, state_province=’MA’, country=’USA’, website=
‘http://www.oreilly.com/’)
>>> p2.save()
>>> publisher_list = Publisher.objects.all()
>>> publisher_list
Publisher: Publisher object, Publisher: Publisher object

Yeehaa, let me know if you have any other questions!

What is it?
If you can guess what pun this represents, I’ll venmo you a dollar.

Task Manager Gem

This little gem caught me at a productive moment.

I was going through a school website, and the tab broke. I thought I was going to have to restart IE and lose all my other tabs. Not that big of a deal, but sometimes annoying.

All I had to do was open task manager. And each instance of IE could be shut down.

Task Manager Screen Clip

Sweet.

No more having to restart the whole program losing a bunch of tabs. Treating each instance of IE makes it easier to manage. And improve workflow. You break a page. No problem, just kill that task.

Sweet Car
Sweet. Like this car. Does anybody know what this is?

Pythons and Visual Studio Development

Two little gems for today.

To run several versions of Python on a windows machine, install whatever versions of python you want, but don’t add them to your path variable. (This will be an option on the second page of the python installer.)

Instead when you want to run a version of Python, call directly to the exe.
ie:
C:/Python27/python.exe
or
C:/Python34/python.exe

This way you can play with all the Pythons you want!
Next is creating a shortcut for this because writing this every time is a bit tedious. Any tips?

Next Tidbit
If you’re using visual studio to develop a python project. You don’t have to run it with python. Simply open command prompt or powershell to the visual studio directory and it acts like any other file system.

eg:
I’m learning Django web framework, but I’m learning from tutorials that are agnostic, so I wasn’t sure if I was going to learn how to run the server or complete unit tests.

But no problems so far. Just treat visual studio like Sublime, and use a command prompt to test your code.

This is how I’m running my server from the command prompt!
C:/Python27/python.exe manage.py runserver

I’m run this below the .sln level
Djangoapp.sln
Djangoapp <---- CD into this file and run. Hooray! [caption id="attachment_1581" align="aligncenter" width="474"]THINK IBM has fight songs. Early adopter of “Company Culture”
Lots of awesome stuff at the Computer History Museum: Click on the photo to find out more. [/caption]

Worth Watching: Rhythm Circle

Why should I watch this?
It’s a great new way to look at Rhythm
Why should I look at Rhythm this way?
Rhythm surround us.
Why does that matter?
It helps us find something we can all relate too!
Why do I wanna relate to you?
So you can understand that our differences aren’t polarizing.
So Rhythm will make me like you?
Maybe not, but it might make you understand why I dance like a noodle.

Worth Reading: What we give away when we log on to a public Wi-Fi network

From the Correspondent and Maurits Martijn is THIS great article highlighting vulnerabilities we subject ourselves to when we join a open Wi-Fi network.

Why should I read this?
Have you ever joined an open Wi-Fi network?
Yes.
This article will open your eyes the dangerous world you’re entering.
How so?
Well personal/private information can be gleaned from your network traffic. And financial info can be stolen or skimmed.
So what am I gonna do? I love free internet!
Here’s a link about how to protect yourself.

Bonus: UX Design in a good looking website.

Park Life Sticker
Matt Thompson a mentor who sits down the hall from me talked to a group of us last week about finding what you love outside of work to keep you focused on your goals. I appreciate that mindset, having a passion will push you to create to your passions end.

Python Resources for SVCC Folks

Badaboom Python on Windows.

For installation: PTVS and Scott Hanselman.

For Learning: iPython Notebooks

For Websites (especially Unix): Matt Harrington

General Help: PTVS Codeplex Documentation

For ideas… That’s up to you!

Does Python tools for Visual Studio entice you? This video lays out features very nicely.

I saw a lizard today… That’s kind of like a Python.

Engaged in the Digital World
I love this photo. Uncle Bill, Matt, and Katie.

Worth Watching: Bill Nye and GMOs

GMOs Explained the Bill Nye way…

Why should I watch this?
GMOs are a complicated and easily warped topic.
So?
Bill makes it easier to understand.
How?
He provides perspective, history, and insight that can be valuable to people unfamiliar with the topic.
So?
If nothing else, you’ll learn some great techniques to become a great teacher.
Cool, sounds good.

Worth Investigating: ESRI’s Zip Lookup

What do the marketers think of you?
This is kinda spooky. Just enter your Zip Code to see what classification of consumer you are assumed to be because of you location.

Here is the link

Why should I look at this?
Ever wondered why you receive certain ads?
So?
Its like a mirror into your materialist soul.
What?
If you were a materialist you would be one of the types highlighted here.
So?
Its interesting, and might make you smile.
Fine, I’ll check it out.
At least take a look at 90210

What’s your lifestyle segmentation?

Bonus: Tesla’s Crazy new Model S.
I can’t wait to argue about this with Ryan Reilly.

Worth Reading: Introducting GIFV

Imgur.com has released a new file format for sharing .GIFs! It’s called .GIFV. It uses MP4 for the magic and loads much quicker and smoother than old school (1987) gifs! Hooray!

Here’s the original article

Why should I read this?
Its going to change mobile and web experiences.
So?
People will have access to richer content without the memory costs and bandwidth usage.
So?
More interactive sites means you could be left behind if you don’t adopt the newest format.
Oh?
Well kinda, stuff will still work, but look at how shiny and smooth the two gifs in the article are. Or these on Reddit.

Dang.

Pink Bucket and Cactus
Cole Hardware has Ladies Night… A hardware store has a ladies night. San Francisco is full of surprises.