Hello World,
I am about creating a web app using django, and i my forms like creating Im using generic CreateView UpdateView… etc
I have some logic and conditions to add and I dont know how to join my logic to the view Im creating.
Thank You
Hello World,
I am about creating a web app using django, and i my forms like creating Im using generic CreateView UpdateView… etc
I have some logic and conditions to add and I dont know how to join my logic to the view Im creating.
Thank You
Hi @Lyounessi
Class based views are great for moving fast but can quickly become hard to extend, as you’re experiencing. Check out:
Hope those help!
Adam
In addition to Adam’s comments, if you want to learn / understand more about the standard Django CBVs, I can recommend the Classy Class-Based Views docs along with the diagrams at https://www.brennantymrak.com/articles/django-class-based-views-diagrams.
Beyond that, if you have any specific questions regarding particular functionality you would like to implement, feel free to ask your questions here.
Thank You Ken,
I wanted to make a condition inside an UpdateView, to stop a user updating other’s articles for exemples
Ok, so there are a couple of ways to handle this -
If I were implementing something like this, my first thought would be to override the get_object method of the View to check to see whether or not that user is allowed to update a particular article. If the user doesn’t have the right permissions, you could either return them to the listing page or throw a 403.
One of the advantages of overriding that particular method is that it’s called on both a GET and a POST, so you have some protection from a person modifying a URL and blindly submitting data.
Ken