This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How add action to admin | |
class PurchaseAdmin(admin.ModelAdmin): | |
actions = [ship] | |
def ship(modeladmin, request, queryset): | |
queryset.update( | |
shipped=True, | |
shipped_at=timezone.now() | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class myProperty: | |
def __init__(self, get_func=None, set_func=None, del_func=None): | |
self.get_func = get_func | |
self.set_func = set_func | |
self.del_func = del_func | |
def __get__(self, instance, cls): | |
if instance is None: | |
return self | |
if self.get_func is None: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ajax jQuery | |
function upload(event) { | |
event.preventDefault(); | |
var data = new FormData($('#ajax').get(0)); | |
console.log(data) | |
$.ajax({ | |
url: '/image_load/', // same url 'action' in form | |
type: 'POST', | |
data: data, |