Python/Django notes from a Ruby/Rails Developer

Posted on May 26, 2019
Tags: python, django, rails, ruby, programming

So, recently I starting working with Python/Django, come from a Ruby/Rails background, I decide keep notes about some points. So here we go:

NOTE: I will keep this post updated as I figure out new things.

Some models don’t follow the rule of use id as the primary key. So always use .pk in order to get the correct primary key

object.pk

Inform the path from where the method is called. In this case, the method foo_bar is used inside the my_app helper.

@mock.patch('my_app.helpers.foo_bar', return_value=10)

If is a object related method, use:

mock.patch.object(Object, 'foo_bar')

You can also use return_value if you need

 mock.return_value = some_thing
obj.refresh_from_db()