Re: Accessing the model attribute of UpdateView & friends

2018-06-07 Thread Mikkel Kromann
Thanks Daniel. I actually tried to implement it in the __init__ but it didn't work. I'll read through your explanation more carefully - I'm sure I could use a bit better understanding on the ways of Python and Django :) Again, thank you for your very useful replies cheers, Mikkel torsdag den 7.

Re: Accessing the model attribute of UpdateView & friends

2018-06-06 Thread Daniel Germano Travieso
I'm glad it helped. As you can see, the dispatch method I wrote does override the default definition, but I return the super() dispatch method, so on the default flow the end result is the same (the validity of the request would be checked anyway, only after you set your class atribute). To avoid

Re: Accessing the model attribute of UpdateView & friends

2018-06-06 Thread Mikkel Kromann
Thanks Daniel. Both your proposed solutions worked very well. For now, I don't have other information stuffed into my model definitions, so the urls.py approach could do. However, if I decide to put more information into models.py, the def dispatch() approach could be useful. One question thou

Re: Accessing the model attribute of UpdateView & friends

2018-06-06 Thread Daniel Germano Travieso
Ok! I think I see your problem. It is a deeper understanding of python classes that may be the problem. You see, "model" and "self" are class atributes of the python class that houses your class based view (as every class in django is first a python class). So, if you try to access the attribute

Re: Accessing the model attribute of UpdateView & friends

2018-06-06 Thread Mikkel Kromann
Hello Daniel. Thank you for your reply. Perhaps I was not explicit enough in describing my problem - it is far simpler than your solution indicates. In my model definitions, I already have a list of the fields to be represented in the form of UpdateView - it is an attribute in the form of a sim

Re: Accessing the model attribute of UpdateView & friends

2018-06-06 Thread Daniel Germano Travieso
Hello! As you see on the documentation ( https://docs.djangoproject.com/en/2.0/topics/class-based-views/) for the class based views, any arguments you pass to the class based view .as_view() method will override attributes of the class based view, so if you set MyCView.as_view(model=Foo) is the sa

Re: Accessing the model attribute of UpdateView & friends

2018-06-06 Thread Mikkel Kromann
Thanks for the advice, Andréas. But the response is the same: File "C:\Users\ ... xxx ... \items\views.py", line 7, in ItemUpdateView fields = self.model.fields NameError: name 'self' is not defined As far as I understood, model is an attribute, not a method (though I'm new to Pyt

Re: Accessing the model attribute of UpdateView & friends

2018-06-05 Thread Andréas Kühne
Hi, Have you tried self.model? It should be present in all methods in the class? Regards, Andréas 2018-06-05 21:56 GMT+02:00 Mikkel Kromann : > Dear Django-users. > > I'm slowly working towards a Django "data-warehouse" framework, where I > can easily add a lot of models (each containing a tab

Accessing the model attribute of UpdateView & friends

2018-06-05 Thread Mikkel Kromann
Dear Django-users. I'm slowly working towards a Django "data-warehouse" framework, where I can easily add a lot of models (each containing a table with data), while sticking to only few reusable views. I've realised that in urls.py, it is possible to specify the model on which the UpdateView i