Skip to main content

Posts

Showing posts with the label dependencies

Django: 'ManyRelatedManager' object is not iterable

Upon development proces you often meet ManyToMany relations that throw errors in templates. I prefer to feed everything to context and play with it there. This kind of error appears when you iterate through a model's ManyToMany field. To fix it just add a related 'all' manager through dot syntax. Like so: Model: class BannerImage ( models . Model ) : image = models . ImageField ( upload_to = "somedir" ) def get_image_url ( self ) : return 'Image url here' class Banner ( models . Model ) : name = models . CharField ( max_length = 250 , null = True ) images = models . ManyToManyField ( BannerImage ) View/Tag or else, that creates context: banner = get_object_or_404 ( Banner , pk = 1 ) return { 'banner' : banner , } Template causing the error: {% for image in banner . images %} < img src = "{{ image.get_image_url }}" /> {% endfor %} Template without the error: {% ...

Django: Virtualenv with Eclipse befrending

Hi! Many people use Virtualenv. It has become common pattern now days. I like Virtualenv but it has no debugger. You can run ' python manage.py runserver ' but it will newer help you see somthing like runtime variables and code flow. I like PyDev  debugger. It helps me a lot. Anyway I faced a problem recently. My employer wants me to run code at virtualenv. I needed to download and run project. I made it creating New virtualenv called 'venv' inside a project folder. Command is: virtualenv - - no - site - packages venv It will create dir 'venv' inside current directory. So you should be at where you need to store your virtualenv (your project directory for e.g.). --no-site-packeges  parameter says that your new virtual environment will not have packages installed in system. It's a must if you want to avoid collisions with newer versions of code. Now we have a dir inside your project called venv  containing our separated python environment. Lets activ...

Django: Better way to install django apps into apps. (Handling django projects dependencies.)

Let's talk about common programming practice. You love to code yourself. Everyday you write tons of code. Making lots of common tasks is interesting and challenging. No? A-ha! You love plugins too! :) I'm making a startup. Everyday there are some ideas coming to my head. Some are easy to implement, some are not, but I often download tons of plugins. There are lots of ways to use plugins without installing them to main system. Python virtualenv is easy and common to use for this purposes. Soon I'll write an article about it too. But the main problem of Python Virtualenv is it's complexity. You basically need to install something, make an environment and so on... What if you just need to implement nice and easy "Django way". Here direct copy comes in mind. It's the easiest way, as for me. Basic concept is:    - download plugin (be it in egg, zip, tar.gz or any other format)    - unpack it     - copy to django app dir ...