For example I have a particular method inside my modelform class. Does Django internally invoke all methods in that class even without me explicitly invoking that method?
Does the is_valid() method internally invoke all methods in my modelform class?Coz I want to create a custom validation method in my form. does django internally call that method?
For form custom validation try using clean() - it will automatically get called with the standard validation.
Related
I have a static method in a class from which I am getting a string which is in the form of link. Now when I am trying to pull the same data in the LWC, I am getting the data as undefined.
Can anyone please explain me if I need to perform any conversion in the logic or I have to add extra logic in JS.
Your Apex method should be annotated with #AuraEnabled(cacheable=true) to be used with LWC.
Then you can simply import your method in LWC using either #wire or imperative Apex.
Checkout the standard documentation here
Please add your code here if you're still having issues.
If you are using Apex, your static method must have #AuraEnabled(cacheable=true) if you wan't to be able to store the data in lwc.
When i select Generate Application Module class and click OK, The AMImpl.java class is generated without any code. what might be the reason for this?
It's because all the code is in the base class.
What do you expect to be in the class?
When you define to create the class, you can choose what will be created (all based on the time you create the class).
Then all methods you write will end up in this class and can be exposed to the client.
Use is described here.
Per the docs:
The base classes of the ADF Business Components framework may be
extended to incorporate custom code with all types of components in
the framework and to extend the ADF Business Components framework
behavior.
When used without customization, your business component is completely defined by its XML document and it will be fully functional
without custom Java code or even a Java class file for the component.
If you have no need to extend the built-in functionality of a
component in ADF Business Components, and no need to write any custom
code to handle its built-in events, you can use the component in this
XML-only fashion. However, when you do extend base classes of the ADF
Business Components framework, you can still work with XML documents
in JDeveloper.
Once you have created framework extension classes, any new business component you create can be based on your customized
framework class instead of the base one. And, you can always update
the definitions of existing components to use the new framework
extension class as well.
Best practice is to create your own set of custom framework extension classes so you have hook points for creating common code for your custom ADF BC EOs and VOs
Should a react class that makes api call (a service) use static methods?
Eg:
class ProductService{
static getAllProducts(){ return fetch(...)}
static saveProduct(){ return fetch(...)}
...
}
Or should I create an instance eg. (new ProductService()).getAllProducts
Or Should I use a singleton pattern
I would rather use static methods because they are simpler and potentially faster. Also, it does not make sense to instantiate a class if there is no state specific to the instance.
Just put your functions for one service in a file my-service.js or my-service.ts and use:
import {myFunction} from "../services/my-service.js.
In reality, you will probably need to create custom hooks, so you can update React contexts or states. For example, to create a service with all your API calls to modify "products": "use-product.ts". This allows to organize your code in multiple services. It is the same way it is done in framework React like Next.js. Static is not a good solution because it will be hard to mock when testing.
Instances raise ESLint error: class-methods-use-this on most methods for a service without state. Singleton pattern seems to be more work, even if backend frameworks and Angular use this method, injecting the singletons.
I am confused about how to process my form(s) using django, django-rest-framework, angularjs, and django-angular.
Using standard Django techniques I can create a model form in my view and pass it to my template.
Using django-angular, I can ensure that the form has lots of pretty bootstrap3 styling and integrates well w/ angularjs.
Using angularjs, I can bind the form to javascript models and gets loads of cool interactive functionality.
Using django-rest-framework, I can load the initial form data via a RESTful API which returns JSON.
This all works great. I am just not sure what to do when submitting my form though...
Should I submit using an angular function that calls my RESTful API? Or should I submit using normal Django methods (ie: if form.is_valid(): form.save()?
I am refactoring this code from a pure Django app and the forms have some extremely complex custom validation methods. I am not sure that I can (or should) replicate that in angular.
Is there a "best practice" out there? Given that I can GET and POST via my RESTful API, what is the advantage to still doing it via Django?
note: I just thought that custom serialization validation should let me have the same level of complexity going through django-rest-framework as I previously had in pure Django. Whether this is a good idea or not is still a valid question.
note2: angularjs & django-rest-framework sure does seem faster.
It is common practice to submit the data through the API and let the serializer do most of the validation for you. You can then do custom validation if needed. You can take a look here for more information on custom validation if you need it. But it does a pretty good job and I rarely have to write any custom validation.
Some of the problems you may run into with trying to do it through pure django, is that it will mess up your SPA. Doing a POST request will require you to "leave the SPA" and return back to it. Other issues such as CSRF tokens are also a pain in the butt to try and figure out. Best to just use your REST API.
Am using a view file,controller and a helper. am accessing data value through webserver.
Steps:
the controller get value from webserver and set it in the view. the view uses the helper to display the data in some format. But my helper again calls the webserver method to get the inner values. Is it correct the helper accessing webservice method? Is it the correct way of programming in mvc?
Thanks,
IMO, a webservice is just another datasource and should be accessed via the model. If it's me, I handle it by either creating a new model for the service call (if the service call is in support of an existing entity, it may make more sense to make the call in that entity's model itself). My controller calls the model method, sends the data to my view which, in turn, forwards that data on to the helper.
This maintains the MVC separation, but still allows the data you need to make it's way into the helper where you need it.
I will tell you what is written in the Ruby on Rails book. I can not remember the title right now but...
Helpers are usually used for view rendering not for server calls.
Hope it helps.