lacetans / faceschool

Social network for educational institutions.
GNU General Public License v2.0
0 stars 1 forks source link

Image management in model #8

Open emieza opened 9 years ago

emieza commented 9 years ago

Add image upload to:

Think about two issues:

moradani commented 9 years ago

12/12/2014

I'll think about it, i'll think about it...

ghost commented 9 years ago

Ok! lets code!

emieza commented 9 years ago

One hint to add images to the model:

For the user profile seems reasonable to use Django backend :)

ghost commented 9 years ago

Finished! (I think...)

ghost commented 9 years ago

For testing go to /register (register new users), or index (view and create new posts)

luchinke commented 9 years ago

I would like to know how an image is stored in django (which directory) to do the src tag in the posts template​ !

ghost commented 9 years ago

you only have to create a new directory under /web named media. You don't have to specify the whole path in the src attribute to the image in the html code, django will do it for us. for example in latest_posts template:

<img src='{{MEDIA_URL}}{{post.image}}' width=40%>

the MEDIA URL is configured in the settings file ('/media/') and post.image will be a folder inside /media named /user_images (you don't have to create it). you can try it in your development environment.

luchinke commented 9 years ago

ty ! Im already installing Pillow. Nice work !

On Thu, Feb 12, 2015 at 11:19 AM, José Pedro Rusakiewicz < notifications@github.com> wrote:

you only have to create a new directory under /web named media. You don't have to specify the whole path in the src attribute to the image in the html code, django will do it for us. for example in latest_posts template:

the MEDIA URL is configured in the settings file ('/media/') and post.image will be a folder inside /media named /user_images (you don't have to create it). you can try it in your development environment.

— Reply to this email directly or view it on GitHub https://github.com/lacetans/faceschool/issues/8#issuecomment-74047711.

ghost commented 9 years ago

why do you need Pillow? I didn't need that!

luchinke commented 9 years ago

Fuck then :/

On Thu, Feb 12, 2015 at 11:27 AM, José Pedro Rusakiewicz < notifications@github.com> wrote:

why do you need Pillow? I didn't need that!

— Reply to this email directly or view it on GitHub https://github.com/lacetans/faceschool/issues/8#issuecomment-74048753.

luchinke commented 9 years ago

web.FSUser.main_image: (fields.E210) Cannot use ImageField because Pillow is not installed. HINT: Get Pillow at https://pypi.python.org/pypi/Pillow or run command "pip install pillow". web.FSUser.profile_image: (fields.E210) Cannot use ImageField because Pillow is not installed. HINT: Get Pillow at https://pypi.python.org/pypi/Pillow or run command "pip install pillow". web.Post.image: (fields.E210) Cannot use ImageField because Pillow is not installed. HINT: Get Pillow at https://pypi.python.org/pypi/Pillow or run command "pip install pillow".

ghost commented 9 years ago

(0_0) what? are you using django v1.7?

luchinke commented 9 years ago

import django django.VERSION (1, 7, 1, 'final', 0)

On Thu, Feb 12, 2015 at 11:31 AM, José Pedro Rusakiewicz < notifications@github.com> wrote:

(0_0) what? are you using django v1.7?

— Reply to this email directly or view it on GitHub https://github.com/lacetans/faceschool/issues/8#issuecomment-74049386.

luchinke commented 9 years ago

We'll check it later, don' worry.

still ty :)

On Thu, Feb 12, 2015 at 11:36 AM, Lu Chinke lucham1995@gmail.com wrote:

import django django.VERSION (1, 7, 1, 'final', 0)

On Thu, Feb 12, 2015 at 11:31 AM, José Pedro Rusakiewicz < notifications@github.com> wrote:

(0_0) what? are you using django v1.7?

— Reply to this email directly or view it on GitHub https://github.com/lacetans/faceschool/issues/8#issuecomment-74049386.

ghost commented 9 years ago

Oh sorry! my mistake! I thought it was included by default. yes you have to install pillow.

luchinke commented 9 years ago

Nice. The next question is :

Did you needed to add columns to sqlite for images?

/// Exception Value: no such column: web_post.image

Exception Location: /home/funky/env/local/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py in execute, line 485

On Thu, Feb 12, 2015 at 11:42 AM, José Pedro Rusakiewicz < notifications@github.com> wrote:

Oh sorry! my mistake! I thought it was included by default. yes you have to install pillow.

— Reply to this email directly or view it on GitHub https://github.com/lacetans/faceschool/issues/8#issuecomment-74050681.

ghost commented 9 years ago

nope. did you makemigrations and migrate? before that, I made another push yesterday.

luchinke commented 9 years ago

Saw it. I updated all today. You forgot an upload_path on Posts. I defined this one as 'posts_images' and created the directory inside media. Ill keep trying with makemigatrions.

ghost commented 9 years ago

here's the post model in the last push i made:

class Post(models.Model):
upload_path = 'users_images'

i'ts working for me. you can look that in https://github.com/lacetans/faceschool/blob/image/web/models.py

allusers images (posts, profile and wall) are saved in users_images.

ghost commented 9 years ago

you don't have to create any directory inside media django will do it for you.

ghost commented 9 years ago

you can try to delete the sqlite db file and try again with makemigrations and migrate.

luchinke commented 9 years ago

Perfect. Thanks!

On Thu, Feb 12, 2015 at 12:33 PM, José Pedro Rusakiewicz < notifications@github.com> wrote:

you can try to delete the sqlite db file and try again with makemigrations and migrate.

— Reply to this email directly or view it on GitHub https://github.com/lacetans/faceschool/issues/8#issuecomment-74057002.

ghost commented 9 years ago

Problema detectat!! després d'enviar un formulari de post, si l'usuari refresca la pàgina es torna a eviar el formulari creant posts duplicats!!! He estat buscant i he trobat això: http://en.wikipedia.org/wiki/Post/Redirect/Get

Ho hauríem d'implementar en Django