BLOG

A LITTLE STORY ABOUT MY JOURNEY

Django Custome Validation model FileField

We can validate field with own validation rule like:

inside models.py

  🙂  

Django get current user globally in the project

Sometimes, you will need to get the current authenticated user in models, or other parts of your app. To achieve this, you must create this middleware in your app(middleware.py) and add it to MIDDLEWARE_CLASSES in project settings: ‘myapp.middleware.GlobalUserMiddlware’

Use Example:

Refrence: http://simionbaws.ro/programming/python-programming/django-python-programming/django-get-current-user-globally-in-the-project/

Check if user belongs to a group in django templates Templatetags

So here comes a simple template filter which checks if the user belongs to a given group. It can be easily extended to take into account more groups. – See more at: http://www.abidibo.net/blog/2014/05/22/check-if-user-belongs-group-django-templates/#sthash.i1cF0nIZ.dpuf

And in your template you can use it this way:

         

Django Model Form Validation

Django model form automatically validate own form while we create form, but some time we add extra field and need validate customisation at this time need to call validation function “clean” for this type of conditions, i have try with following code, you can also try :

Django Model Admin get_list_display_links

While we need links on different column we can use “get_list_display_links” function default given by Django framework and we simply define links with condition also like:

🙂

1 2 3