##Day 2!
-
In a tuple such as:
GENDER_CHOICES = ( ("M", "Male"), ("F", "Female"), ("?", "Unknown") )… within
models.py, the first value is written into the database. The second value is the value that is displayed for the user.</li> -
After writing up models.py, you need to run these two migrations to sync the database:
python manage.py makemigrations academy python manage.py migrate academy -
Adding the
-pflag can make TWO directories! For example:mkdir -p project/subdirectory1/subdirectory2 -
By default,
BASE_DIRis set to the root of your project file — the same spot where you can findmanage.py. - open(): https://docs.python.org/2/library/functions.html#open </ul>
- OMG THIS INSIDE admin.py IS MAGIC:
*csv.DictReader(open(csv_file)) will return a list with each row in the file as a dictionary.
from django.contrib import admin
from academy.models import Invite
class InviteAdmin(admin.ModelAdmin):
list_display = ("name", "branch", "gender", "date_of_birth", "race")
list_filter = ("branch", "gender", "race")
search_fields = ("name",)
admin.site.register(Invite, InviteAdmin)
*If you just want to ‘deploy’ a site so that it’s available to other users in your intranet network (e.g. other people in your office), try this: 1) Find your IP address by typing ifconfig into your command line. 2) Run $ python manage.py runserver 0.0.0.0:8000 in your terminal. 3) Paste in http://[IP ADDRESS]:8000/admin/ into your browser. Theoretically, this should work, but it did not work for me just now. :(
-
Every time you change your models, in newer versions of Django, run something like:
python manage.py makemigrations appname. Every time a migration is run, a file will be added to/appname/migrations. Next, you have to actually run the migration:python manage.py migrate academy. -
list_displayis awesome. So islist_editable.
Thanks much to http://first-django-admin.readthedocs.org/en/latest/ for the surprisingly straightforward and short django tutorial.
This post is a part of the #100daysofcode challenge.
##Day 1: Random Note to self: if a div inside a div isn't recognizing the parent div as a parent when it's set toposition: absolute, it's because the closest parent needs to be set to position: relative. Otherwise, it'll default to position: static. (CSS)
Meteor.startup() { } is sort of like $(function() {}); except we use it with meteor. (MeteorJS)
Adjust the height of a textarea with its content: $('textarea').css('height', 'auto');
$('textarea').height(this.scrollHeight);
If you want the ability to write markdown inside your WordPress posts, see:http://www.elegantthemes.com/blog/tips-tricks/using-markdown-in-wordpress. (I decided on using the PrettyPress Editor.) </li>
git fetch upstream branchname and git merge upstream branchname
view:source but can't find it inside the browser elements tab, chances are it's because there was a .remove() put on the elements. (JS)
localStorage is nice and lighter weight than cookies.
Intl.DateTimeFormat().resolvedOptions().timeZone ? Intl.DateTimeFormat().resolvedOptions().timeZone returns the users's timezone! However, this is currently supported on only very limited modern browsers. (JS)
This post is a part of the [#100dayosfcode](http://www.thecodingdiaries.com/the-100daysofcode-challenge/) challenge.