2

when ever i override the change_view in admin i will get the following line of code

@csrf_protect_m
@transaction.commit_on_success
def change_view(self, request, object_id, extra_context=None):
    return admin.ModelAdmin.change_view(self, request, object_id, extra_context=extra_context) 

What is the First two line of code ?? Should i use this ?? What it does ?

I am just started Extending Django Admin. So hope your answers will be simple and with example.

Abhilash Joseph
  • 1,196
  • 1
  • 14
  • 28
  • 2
    It's called decorator, you should have a look at [this question](http://stackoverflow.com/questions/739654/understanding-python-decorators) – Nicolas Nov 07 '12 at 08:18

1 Answers1

3

@csrf_protect_m is a method decorator. To understand what its doing, read the documentation on csrf protection

@transaction.commit_on_success is also a decorator. To understand what its doing, read the documentation on database transactions

Decorators in simple terms are a way to wrap conditional functionality around methods or functions. They wrap around a function, modify it, and return the function. The python manual has an explaination of how they are written.

Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284