How to get list of methods in Odoo Models? - list

I'm using odooV10.
I want to know every model's methods without searching it manually, but I couldn't find anywhere to achieve this. Is anyone have any idea?

well you can simply dir(model)
ie.
any_method_on_your_model(self):
print dir(self)
you will see all the properties included in the object.

Activate the Developer Mode in OdooV10.
Then go Setting(odoo Main Settings)--> Technical -->Models.
Here you can find all models, fields, views and constraints. I hope this will work for you.
if not explain what you want trying to do.?

In python you can get method of class
get methods of class
but the problem here odoo inherits mechanism prevent you from doing
this. when you call a method a very complicated operation to create
an object with that method from the inherited classes

Related

(GCBV) How to call custom method to publish blog (UpdateView)

Good day SO!
Next to Java I'm trying to learn some Python/Django since the company I work for is also going to use Django. However, I am trying to figure out how to work with Generic Class Based Views. I hope somebody can give me some information to guide me in the right direction to solve my problem.
I have a small blog application containing CRUD (Create, Read, Update, Delete) abilities with GCBV (Generic Class Based Views). In the Detail view I have a link to publish:
{% url 'blogs:publish' blog.pk %}
which i want to use like:
url(r'^(?P[0-9]+)/publish/$', xxx, name='publish')
I just can't get it to work. I have attempted (and simular attempts) to create a method in the Update(UpdateView) class called publish(self, **kwargs): and make the url pattern to call it:
url(r'^(?P[0-9]+)/publish/$', views.Update.publish(), name='publish')
which obviously doesn't work, otherwise you wouldn't be reading this right now ;) I've been reading quite some docs/google/etc, but mostly it's function based or the tutorial stops after CRUD. Can you push me in the right direction (tip/clear tutorial/example) or an explanation where I'm taking the wrong choices? Thanks in advance!
UpdateView is used for updating, but you may take a look at CreateView. It is used to create objects.
Also you need to understand that you can't call a method as it's even hard to imagine how it has to work. GCBV are just sequences of already written methods which make your life easier. You can overwrite GCBV basic methods and create your own, which then can be used inside the view, but you can't call them in the urls.

Check which fields are changed in Django

I have a model with many fields. I need to run a code only when two specific fields are changed. I know I can modify my model's save() method but I don't know how to check which fields are changed in my ModelForm.
Sorry because i cant give you any code snippet since i am not very experienced in Django, but i would go for getting a signal when a change is done through a controler class listening on the models and hearing for changes. Hope i might helped a bit.
Good luck
Django-model-utils has something called a FieldTracker that does exactly this. Just instantiate it in your model and tell it to track the specific fields you're looking for. Then you can use the has_changed method to test if a given field has changed since the last save.
This package has some other great utilities as well, I really recommend looking through the docs.
You could try django-dirtyfields.

local fields list not overriding correctly in Django-piston

Has anyone experience issues with this but in Django-piston that doesn't allow you to override fields already set?
https://bitbucket.org/jespern/django-piston/issue/192/object-handler-fields-override-local-field
Can anyone help me with a work around? I saw there is an easy patch but I don't want to go in and change the code in piston. Is there a way around it?
I'm using django-piston for quite a long time. There are a couple of issues with when you specify model = Foo. I simply use it to organize web service's urls, OAuth and Django Authentication. I still dont have any issue with it (yet). If you dont have any special reason to use model = Foo and fields I think you can call the model within read and create.
Hope it help :)
If you dont want to apply the patch yourself, and you dont want to avoid using certain model references on handlers to work around the issue, then maybe just clone the fork of piston that contains the patch being pushed to the main repo:
https://bitbucket.org/rptirrell/django-piston/overview
Its up to date aside from that and its trivial to swap it out to the main repo whenever you want.

How to override a related set's "add" method in Django

I am working on a Django project and I want to send a signal when something gets added to some model's related set. E.g. we have an owner who has a set of collectables, and each time the method owner.collectable_set.add(something) is getting called, I want a signal like collectable_added or something. Signals are clear to me, but I don't know which manager(?) contains the "add" method that I want to override.
Edit for Xavier's request to provide more details: you can easily override a model’s save method, by simply defining it and calling the "super-save" so it gets properly saved with some extra functionality. But I wonder where to override a related set's add method.
Gosh, I think I haven't brought in any further details, but I think it should be clear what I want to do even from the first paragraph.
Edit 2: This is the method I want to override. Is it recommended to do so, or do you suggest another way to place the sending of the signal?
This is the solution I found, the m2m_changed signal. Took me quite some searching and reading. Furthermore, I found out that it is not trivial to extend the ManyRelatedManager class, which would have been the other option. But with the m2m_changed signal I can rely on built-in functions which is the preferred way most of the time.
I think you're looking for the RelatedManager Class.
After much searching (thanks to this Paul's hint), I came across this snippet that helped to explain the m2m_changed implementation to intercept not override the add method on the ManyRelatedManager. It appears that the manager on a many-to-many relationship happens on the fly, so it's not trivial to override the method.

Using instance methods with Django Model

I'm trying to implement for methods for eac Model object in my project. get_all() , get_by_id(),add(),remove() and maybe others.
I need to use them by each object . When I declare an object automatically can call one of those methods.
The problem , I don't want to duplicate the code of the four methods in each class .
Is there a way to write them once, and link them to each object.
I heared about instance methods in python.
How can use this.
Please a help
Thanks
...
You can have a base manager which has all these methods and inherit them. Django model and manager inheritance
class MyModel(models.Model):
def get_all():
return <something>
class A(MyModel):
pass
class B(MyModel):
pass
You really should seperate row-level actions (like delete(), get_some_calculated_attribute()) which go in Model classes from table level actions (like create(), filter()) which go in Manager classes.