Tips for Django

* DJANGO GROUPS - A group describes a group of users. One user can be part of many groups and one group can have many users. Groups can use of labeling users. 

 * get_user_model is more convenient than simple User model, it return currently active user model.

* ResizedImageField :- It resizes images when uploaded and stores them for you.

* *args are used when we don't know how many parameters we have to pass, args store all the input in the form of a list.

* **Kwargs are used when we don't know how many parameters we have to pass, **kwargs store all the input in the form of dictonary.

* We can override the delete method tooo in our django models.

* you can remove the default Group model in Django admin panel by using admin.site.unregister(Group)

* signal.py file :- basically this tells us as soon as an instance of the model is created call this function like that thing, there are four types of signals: - pre save , post save, pre delete and post delete.

* Get Absolut URL:- First of all, when it comes to web development you really want to avoid hard coding paths in your templates. The reason for this is that paths might change, and it will be a hassle to go through all your HTML and templates to find every single URL or path and update it manually. It makes your code much harder to maintain.

The solution to this is to define functions that return the URL instead. This is where get_absolute_url() comes into the picture.


* Meta class in models.py - Meta inner class in Django models:

This is just a class container with some options (metadata) attached to the model. It defines such things as available permissions, associated database table name, whether the model is abstract or not, singular and plural versions of the name etc.


* How to use get_object_or_404() in a Django Project? This function calls the given model and get object from that if that object or model doesn't exist it raise 404 error.



* 


Comments

Popular posts from this blog

Django

JS

chat model