Posts

Django Foreign Key to_field -

i have 2 models customuser , magazine random/unique slug fields. want create third model (article) foreign keys slug field: class customuser(abstractbaseuser): slug = randomslugfield(length=6, unique=true) ... class magazine(models.model): slug = randomslugfield(length=6, unique=true) name = models.charfield() class article(models.model): magazine = models.foreignkey(magazine, to_field='slug') author = models.foreignkey(settings.auth_user_model, to_field='slug') but when migrate database create article model, following error: django.core.exceptions.fielddoesnotexist: customuser has no field named 'slug' but customuser has field named 'slug'. , magazine model don't error. has idea going wrong? i use package slug field: https://github.com/mkrjhnsn/django-randomslugfield edit: here full customuser model: class customuser(abstractbaseuser, permissionsmixin): slug = randomslugfield(length=6, exclude_upp...

python - Why can't I remove quotes using `strip('\"')`? -

i can remove left quotes using str.strip('\"') : with open(filename, 'r') fp : line in fp.readlines() : print(line) line = line.strip('\"') print(line) part of results: "route d'espagne" route d'espagne" using line.replace('\"', '') gets right result: "route d'espagne" route d'espagne can explain it? your lines not end quotes. newline separator part of line , not removed when reading file, unless include \n in set of characters stripped " going stay. when diagnosing issues strings, produce debug output print(repr(line)) or print(ascii(line)) , make non-printable or non-ascii codepoints visible: >>> line = '"route d\'espagne"\n' >>> print(line) "route d'espagne" >>> print(repr(line)) '"route d\'espagne"\n' add \n str.strip() argument: ...

javascript - How to drag and drop ONLY if there is no child in droppable div? -

ok, haven't been able work out solution this. i found answer helps reject drops if there draggable element in droppable slot, haven't been able make slot restart accepting children once has been emptied. also, doesn't work initial state of draggable pieces (notice can stack more 1 piece in slot if initial state of child). here link project and here specific piece of code: jquery(window).on("load",function() //if document has loaded { //code executed when document loads here $( ".b-piece" ).draggable({ cursor: "move", revert: "invalid"}); $( ".grid-b .grid-slot" ).droppable({ accept: ".b-piece", drop: function(event, ui) { $(this).droppable('option', 'accept', 'none'); /* stop accepting objects */ $(this).append(ui.draggable); /* move drag object new parent */ $(this).children(".game-piece").css({"top":"0", "left":"0...

remove "latest files" from Drupal module FileDepot -

how can prevent drupal module "filedepot" displaying "latest files" when user first enters file depot? is possible have display nothing until user clicks on folder? in sites/all/modules/filedepot/lib-ajaxserver.php added 1=2 and sql may check original one. worked me // default view - latest files if (!empty($filedepot->allowableviewfolderssql)) { if ($filedepot->ogmode_enabled) { if (!empty($filedepot->allowablegroupviewfolderssql)) { $sql .= "where 1=2 , file.cid in ({$filedepot->allowablegroupviewfolderssql}) "; } else { $sql .= "where 1=2 , file.cid in ({$filedepot->allowableviewfolderssql}) "; } } elseif (!user_access('administer filedepot', $user)) { if (empty($filedepot->allowableviewfolderssql)) { $sql .= "where 1=2 , file.cid null "; } else { $sql .= "where 1=2 , file.cid in ({$filedepot->allowableviewfolderssql}) ...

c# - JSON to Dynamic Object vs. Strongly Typed Object -

i'm not sure if don't big picture or if miss benefits of parsing json-string dynamic object? if have class this class product { public string name { get; set; } public double price { get; set; } public string category { get; set; } } and use httpclient object this product product = await response.content.readasasync<product>(); what benefit code? string content = await response.content.readasstringasync(); dynamic product = jobject.parse(content); if want use them need write product.name with typed apporach @ least have intellisense. if service changes product dynamic approach doesn't me either because still need access mentioned above. so missing? why should use dynamics or when? you always prefer use strong type on dynamic (performance\convenience). here cases use dynamic: when want parse xml , dont want work xelement's, xpath's etc. com interop - makes things easy , nice (try working excel\word , convinced...

node.js - Browser page refresh gets a new session cookie/id -

i having issue in application. whenever browser refreshes reassign cookie new content , new session id. right behavior of browser? the application uses express , connect-tedious libraries of nodejs. user gets logged out because cookie content , session id different whenever refresh. suggestion on how go resolving problem? if node server code responsible setting cookies user , session (using set-cookie header or generating javascript file client same), should check existing cookies in request. when page reloaded, request come server again. @ point can read cookies passed server (which include cookie session , user set last time). if these cookies found , valid, server should not generate new cookie same. even if logic not reside on server , part of client side js, overall idea same. not create new cookies, if can read existing ones correctly.

javascript - Ext js package build -

sencha command let create, build , distribute own package. ext js library built using sencha command. i wonder correct way have built-package have in correct order, list of singleton files in root folder , there no dependency among each other. example, sencha core package, there ext.js, componentquery.js, etc., how sencha command knows build ext.js first. this bit puzzling me. have similar situation. have package, let's call mycoolstuff, in root source folder, have coolstuff.js , list of singleton/utility files, example, coolstuffeventhandler.js. absolutely need coolstuff.js built first, far have no luck. how did ext js it? when define classes, no matter singletones or not, specify dependencies using requires , uses directives: ext.define('coolstuffeventhandler', { //// requires: [ 'coolstuff' ], ///// }); that's all! rest taken care of sencha cmd you.