Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes from notes #14

Merged
merged 8 commits into from
Jul 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Heroku uses git repository to manage your project files, so we need to use it to
Create `.gitignore` file with following content:

venv
*.pyc
__pycache__
staticfiles

and save it. The dot on the begining of the name file is important! This will tell Heroku to ignore this file and don't use it.
Expand Down
2 changes: 1 addition & 1 deletion django_admin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Make sure that at least two or three (but not all) have publish date set. It wil

![Django admin](images/edit_post.png)

If you want to know more about the Django admin, you should check Django's documentation: https://docs.djangoproject.com/en/dev/ref/contrib/admin/
If you want to know more about the Django admin, you should check Django's documentation: https://docs.djangoproject.com/en/1.6/ref/contrib/admin/

It is probably a good moment to grab a coffee (or tea) and eat something sweet. You created your first Django model - you deserve a little treat!

Expand Down
13 changes: 6 additions & 7 deletions django_forms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,13 @@ Basically we have two things here: we save the form with `form.save` and we add
Finally, it would be awesome if we can immediatelly go to `post_detail` page for newly created blog post, right? To do that we need more imports:

from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.shortcuts import redirect

Add them at the very beginning of your file. And now we can say: go to `post_detail` page for a post.

return HttpResponseRedirect(reverse(post_detail, kwargs={'pk': post.pk}))
return redirect('blog.views.post_detail', pk=post.pk)

`post_detail` is a name of the view we want to go to. Remember that this view required a `pk` variable? To pass it to the views we use `kwargs={'pk': post.pk}`, where post is newly created blog post!
`blog.views.post_detail` is a name of the view we want to go to. Remember that this view required a `pk` variable? To pass it to the views we use `pk=post.pk`, where post is newly created blog post!

Ok, we talked a lot, but we probably would like to see how the whole view looks like, right?

Expand All @@ -200,7 +200,7 @@ Ok, we talked a lot, but we probably would like to see how the whole view looks
post = form.save(commit=False)
post.author = request.user
post.save()
return HttpResponseRedirect(reverse(post_detail, kwargs={'pk': post.pk}))
return redirect('blog.views.post_detail', pk=post.pk)
else:
form = PostForm()
return render(request, 'blog/post_edit.html', {'form': form})
Expand Down Expand Up @@ -228,7 +228,6 @@ Open `blog/post_detail.html` and add this line:
so that the template will look like:

{% extends 'mysite/base.html' %}
{% load future %}

{% block content %}
<div class="date">
Expand Down Expand Up @@ -257,7 +256,7 @@ Let's open a `blog/views.py` and add at the very end of the file:
post = form.save(commit=False)
post.author = request.user
post.save()
return HttpResponseRedirect(reverse(post_detail, kwargs={'pk': post.pk}))
return redirect('blog.views.post_detail', pk=post.pk)
else:
form = PostForm(instance=post)
return render(request, 'blog/post_edit.html', {'form': form})
Expand All @@ -282,7 +281,7 @@ Feel free to change the title or the text and save changes!

Congratulations! Your application is more and more complete!

If you need more information about Django forms you should read the documentation: https://docs.djangoproject.com/en/dev/topics/forms/
If you need more information about Django forms you should read the documentation: https://docs.djangoproject.com/en/1.6/topics/forms/

We prepared some extra tasks for you, but they are not very hard. You can do them as a homework:
- create a page with all __draft__ posts
Expand Down
6 changes: 3 additions & 3 deletions django_installation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ Ok, we have all important things in place. We can finally install Django!

## Installing Django

Now, when you have your `virtualenv` started, you can install Django using PIP. In console/command-line you type `pip install django==1.6.4`.
Now, when you have your `virtualenv` started, you can install Django using PIP. In console/command-line you type `pip install django==1.6.5`.

(blog) ~$ pip install django==1.6.4
Downloading/unpacking django==1.6.4
(blog) ~$ pip install django==1.6.5
Downloading/unpacking django==1.6.5
Installing collected packages: django
Successfully installed django
Cleaning up...
Expand Down
8 changes: 4 additions & 4 deletions django_models/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ Let's open `blog/models.py`, remove everything from it and write code like this:
title = models.CharField(max_length=200)
text = models.TextField()
created_date = models.DateTimeField(
default=timezone.now())
default=timezone.now)
published_date = models.DateTimeField(
blank=True, null=True)

def publish(self):
self.published_date = timezone.now()
self.save()

def __unicode__(self):
def __str__(self):
return self.title

It is scary, right? But no worries, we will explain what these lines mean!
Expand All @@ -133,11 +133,11 @@ Now we define properties we where talking about: `title`, `text`, `created_date`
- `models.DateTimeField` - this is a date
- `models.ForeignKey` - this is a link to another model

We will not explain every bit of code here, since it would take too much time. You should take a look at Django's documentation, if you need to know more about Model fields (properties) and how to define things other than things described above (https://docs.djangoproject.com/en/dev/ref/models/fields/#field-types).
We will not explain every bit of code here, since it would take too much time. You should take a look at Django's documentation, if you need to know more about Model fields (properties) and how to define things other than things described above (https://docs.djangoproject.com/en/1.6/ref/models/fields/#field-types).

What about `def publish(self):`? It is exactly our `publish` method we were talking about. `def` means that this is a function/method. `publish` is a name of the method. You can change it, if you want. The rule is that we use lowercase and underscores instead of whitespaces (i.e. if you want to have method that calculates average price you could call it `calculate_average_price`).

Methods very often `return` something. There is an example of that in the `__unicode__` method. In this scenario, when we call `__unicode__()` we will get a text (**string**) with a Post title.
Methods very often `return` something. There is an example of that in the `__str__` method. In this scenario, when we call `__str__()` we will get a text (**string**) with a Post title.

If something is still not clear about models, feel free to ask you coach! We know, it is very complicated, especially when you learn what objects and functions (method) are at the same time. But hopefully, it looks sligthly less magic for you now!

Expand Down
2 changes: 1 addition & 1 deletion django_orm_querysets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ So finally our `views.py` file should look like this:

That's it! Time to go back to our template and display this queryset!

If you want to read a little bit more about querysets in Django you should look here: https://docs.djangoproject.com/en/dev/ref/models/querysets/
If you want to read a little bit more about querysets in Django you should look here: https://docs.djangoproject.com/en/1.6/ref/models/querysets/



Expand Down
2 changes: 1 addition & 1 deletion domain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ In this chapter we will teach you how to buy a domain and direct it to Heroku!

## Where to register a domain?

A typical domain costs around $15 a year. There are cheaper and more expensive options, depending on the provider. There are a lot of companies that you can buy a domain from: a simple [google search](https://www.google.pl/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=register%20domain) give hundreds of options.
A typical domain costs around $15 a year. There are cheaper and more expensive options, depending on the provider. There are a lot of companies that you can buy a domain from: a simple [google search](https://www.google.com/search?q=register%20domain) give hundreds of options.

Our favourite one is [I want my name](https://iwantmyname.com/). They advertise as "painless domain management" and it really is painless. We asked them if they wanted to support Django Girls and they gave us a 20% discount code for you! :) Ask organizers or coaches for it!

Expand Down
1 change: 0 additions & 1 deletion extend_your_application/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ We will create a file in `blog/template/blog` called `post_detail.html`.

It will look like this:
{% extends 'mysite/base.html' %}
{% load future %}

{% block content %}
<div class="date">
Expand Down
7 changes: 3 additions & 4 deletions homework_add_more_to_your_website/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ This line `Post.objects.filter(published_date__isnull=True).order_by('created_da
Ok, the last bit is of course a template! Create a file `blog/templates/blog/post_draft_list.html` and add the following:

{% extends 'mysite/base.html' %}
{% load future %}

{% block content %}
{% for post in posts %}
Expand Down Expand Up @@ -74,7 +73,7 @@ and finally, a view (as always, in `blog/views.py`):
def post_publish(request, pk):
post = get_object_or_404(Post, pk=pk)
post.publish()
return HttpResponseRedirect(reverse(post_detail, kwargs={'pk': pk}))
return redirect('blog.views.post_detail', pk=pk)

Remember, when we created a `Post` model we wrote a method `publish`. It looked like this:

Expand Down Expand Up @@ -107,11 +106,11 @@ Now, time for a view! Open `blog/views.py` and add this code:
def post_remove(request, pk):
post = get_object_or_404(Post, pk=pk)
post.delete()
return HttpResponseRedirect(reverse(post_list))
return redirect('blog.views.post_list')

The only new thing is to actually delete a post. Every Django model can be deleted by `.delete()`. It is as simple as that!

And this time, after deleting a post we want to go to the webpage with a list of posts, so we are using `HttpResponseRedirect`.
And this time, after deleting a post we want to go to the webpage with a list of posts, so we are using `redirect`.

Let's test it! Go to the page with a post and try to delete it!

Expand Down
6 changes: 3 additions & 3 deletions install_python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ Django is written in Python. We need it to do anything in Django. Let's start wi

### Windows

You can download Python for Windows from the website https://www.python.org/download/releases/3.4.0/. After downloading the ***.msi** file, you should execute it (double-click on it) and follow the instructions there. It is important to remember the path (the folder) where we installed Python. It will be needed later.
You can download Python for Windows from the website https://www.python.org/download/releases/3.4.1/. After downloading the ***.msi** file, you should execute it (double-click on it) and follow the instructions there. It is important to remember the path (the folder) where we installed Python. It will be needed later.

### Linux

It is very likely that you already have Python installed out of the box. To check if you have it installed (and which version it is), you type in a console:

$ python --version
Python 3.4.0
Python 3.4.1

If you don't have Python installed or you want a different version, you can install it as follows.

Expand All @@ -40,7 +40,7 @@ Yout type in the console:

### OS X

You need to go to the website https://www.python.org/downloads/release/python-340/ and install the appropriate package for you operating system.
You need to go to the website https://www.python.org/downloads/release/python-341/ and install the appropriate package for you operating system.

----

Expand Down
4 changes: 2 additions & 2 deletions try_python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ To start tinkering with Python, we need to open up a *prompt* on your computer.
A window should pop up on your screen. This window is a prompt, waiting for commands from you. We want to open up a Python console, so type in `python` and hit Enter.

(workshops) ~$ python
Python 3.4.0 (...)
Python 3.4.1 (...)
Type "copyright", "credits" or "license" for more information.
>>>

Expand Down Expand Up @@ -182,7 +182,7 @@ If you want to only read the first number, you can do this by using index. The f

As you can see, you can access different objects in your list by using its name and index number inside of brackets.

You can find a list of all available list methods here in Python documentation: https://docs.python.org/2/tutorial/datastructures.html
You can find a list of all available list methods here in Python documentation: https://docs.python.org/3/tutorial/datastructures.html

### Summary

Expand Down