last

Django create custom UserCreationForm

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I enabled the user auth module in Django, but when I use UserCreationForm he ask me only username and the two password/password confirmation fields. I want also email and fullname fields, and set to required fields. I've done this: from django.contrib.auth.forms import UserCreationForm from django import forms from django.contrib.auth.models import User class RegisterForm(UserCreationForm): email = forms.EmailField(label = "Email") fullname = forms.CharField(label = "Full name") class Meta: model = User fields = ("username", "fullname",

How do I undo the last Add-Migration command?

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have created a migration using the Add-Migration command, but I'd like to change the name of that migration. How can I undo the migration command, so that I can regenerate it using the new desired name? Is it just a matter of deleting the generated files, or this could be a bad idea? 回答1: If you haven't used Update-Database you can just delete it. If you've run the update then roll it back using Update-Database -TargetMigration "NameOfPreviousMigration" , then delete it. Reference: http://elegantcode.com/2012/04/12/entity-framework

How to shift zero in the last column of a matrix

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have one matrix like below- A=[1 1 1 1 1; 0 1 1 1 2; 0 0 1 1 3] But I want to place all the 0 at the end of the row, so A should be like- A=[1 1 1 1 1; 1 1 1 2 0; 1 1 3 0 0] How can I do this? Matlab experts please help me. 回答1: There you go. Whole matrix, no loops, works even for non-contiguous zeros: A = [1 1 1 1 1; 0 1 1 1 2; 0 0 1 1 3]; At = A.'; %// It's easier to work with the transpose [~, rows] = sort(At~=0,'descend'); %// This is the important part. %// It sends the zeros to the end of each column cols = repmat(1:size(At,2),size

Last not empty cell in row; Excel VBA

匿名 (未验证) 提交于 2019-12-03 01:57:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an excel sheet in which I need to find the last non empty cell in a specific column. How do I do this? The below will select this for me, but it will select the first not empty cell, I need the last not empty cell in the row. Worksheets("DTCs").Range("A29").End(xlToRight).Select 回答1: I think it might work just search from the other direction, so something like: Worksheets("DTCs").Range("IV29").End(xlToLeft).Select Though maybe the IV would need to be changed to something else depending on the version of Excel (this seems to work in

Last segment of URL

匿名 (未验证) 提交于 2019-12-03 01:57:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How do I get the last segment of a url? I have the following script which displays the full url of the anchor tag clicked: $(".tag_name_goes_here").live('click', function(event) { event.preventDefault(); alert($(this).attr("href")); }); If the url is http://mywebsite/folder/file how do I only get it to display the "file" part of the url in the alert box? 回答1: You can also use the lastIndexOf() function to locate the last occurrence of the / character in your URL, then the substr() function to return the substring starting from that location:

Script to remove Python comments/docstrings

匿名 (未验证) 提交于 2019-12-03 01:53:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Is there a Python script or tool available which can remove comments and docstrings from Python source? It should take care of cases like: """ aas """ def f (): m = { u 'x' : u 'y' } # faake docstring ;) if 1 : 'string' >> m if 2 : 'string' , m if 3 : 'string' > m So at last I have come up with a simple script, which uses the tokenize module and removes comment tokens. It seems to work pretty well, except that I am not able to remove docstrings in all cases. See if you can improve it to remove docstrings. import cStringIO import

How can I get the Windows last reboot reason

匿名 (未验证) 提交于 2019-12-03 01:52:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'd like to know what is the Windows API function (if any exists) that provides information about the last Windows reboot source. There are three main possible causes: The computer crashed on a blue screen A user or a program shutdown/restarted the computer A power lost The more details I can get the better. However, I need to know at least which reason it is from the main ones. I need to support Windows Vista and Windows 7. Answer: It seems that there is no direct API to get that information. Instead, we have to harvest the

How can you move the cursor to the last position of a textarea in Javascript?

匿名 (未验证) 提交于 2019-12-03 01:49:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a textarea and a button on a form. The textarea may already have some text in it. I would like the cursor to move to the last position in the text area when the button is clicked. Is this possible? 回答1: By “the last position”, do you mean the end of the text? Changing the ‘.value’ of a form field will move the cursor to the end in every browser except IE. With IE you have to get your hands dirty and deliberately manipulate the selection, using non-standard interfaces: if (browserIsIE) { var range= element.createTextRange(); range

HTML Table, first and last column fixed width and columns between dynamic, but equal width

匿名 (未验证) 提交于 2019-12-03 01:49:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is it possible to have a table with width 100% (so the table fits the screen size), where the first and the last column have a fixed width, and the columns between take the rest, both 50%. Like: +--------------------+--------------------------------------+--------------------------------------+------------+ | width:300px; | with dynamic, equals next column | width dynamic, equals prevous column | width:50px;| +--------------------+--------------------------------------+--------------------------------------+------------+ +-------------------

How to select last N records from a table in mysql

匿名 (未验证) 提交于 2019-12-03 01:49:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This code can be used to select the first ten records from a table in mysql. How can I do the same to display last ten records from a table which has 1000 records. I want to display the name in asc order dont want to change that. SELECT name, cost FROM test orderby name asc LIMIT 10 ; 回答1: SELECT q.name, q.cost FROM (SELECT name, cost FROM test ORDER BY name DESC LIMIT 10) q ORDER BY q.name ASC; 回答2: The LIMIT clause can take two parameters, which will provide an offset: The LIMIT clause can be used to constrain the number of rows returned