default-value

Django: How to set initial values for a field in an inline model formset?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-29 07:00:52
问题 I have what I think should be a simple problem. I have an inline model formset, and I'd like to make a select field have a default selected value of the currently logged in user. In the view, I'm using Django's Authentication middleware, so getting the user is a simple matter of accessing request.user . What I haven't been able to figure out, though, is how to set that user as the default selected value in a select box (ModelChoiceField) containing a list of users. Can anyone help me with

Preparing a MySQL INSERT/UPDATE statement with DEFAULT values

感情迁移 提交于 2019-12-28 06:28:15
问题 Quoting MySQL INSERT manual - same goes for UPDATE: Use the keyword DEFAULT to set a column explicitly to its default value. This makes it easier to write INSERT statements that assign values to all but a few columns, because it enables you to avoid writing an incomplete VALUES list that does not include a value for each column in the table. Otherwise, you would have to write out the list of column names corresponding to each value in the VALUES list. So in short if I write INSERT INTO table1

Good uses for mutable function argument default values?

时间秒杀一切 提交于 2019-12-28 04:59:09
问题 It is a common mistake in Python to set a mutable object as the default value of an argument in a function. Here's an example taken from this excellent write-up by David Goodger: >>> def bad_append(new_item, a_list=[]): a_list.append(new_item) return a_list >>> print bad_append('one') ['one'] >>> print bad_append('two') ['one', 'two'] The explanation why this happens is here. And now for my question: Is there a good use-case for this syntax? I mean, if everybody who encounters it makes the

Passing an empty array as default value of an optional parameter [duplicate]

[亡魂溺海] 提交于 2019-12-27 11:47:12
问题 This question already has answers here : Setting the default value of a C# Optional Parameter (3 answers) Closed 6 years ago . How does one define a function that takes an optional array with an empty array as default? public void DoSomething(int index, ushort[] array = new ushort[] {}, bool thirdParam = true) results in: Default parameter value for 'array' must be a compile-time constant. 回答1: You can't create compile-time constants of object references. The only valid compile-time constant

x:Static value in Control does not update

别等时光非礼了梦想. 提交于 2019-12-25 16:49:52
问题 I would love to understand a special part about WPF. I am setting a GridLength (width) value for a ColumnDefinition inside a Control. The value is referencing a static Property of a static class. Of course it does not support INotifyPropertyChanged but all I want is to update the value and when the next instance of this Control gets created it should take the new value. But it doesn't work this way. I experienced the same behaviour when binding to a dependency property that gets its default

Specifying default value for a field for table creation in postgresql

拜拜、爱过 提交于 2019-12-25 07:58:20
问题 Following is my table design: CREATE TABLE "x"."y"( "z" timestamp NOT NULL, "a" Timestamp NOT NULL DEFAULT z + 18 months, ) WITH (OIDS=FALSE) ; How do I specify the default value of 'a'? Can I specify this at the time of the table creation? 回答1: As postgresql documentation states The DEFAULT clause assigns a default data value for the column whose column definition it appears within. The value is any variable-free expression ( subqueries and cross-references to other columns in the current

Specifying default value for a field for table creation in postgresql

▼魔方 西西 提交于 2019-12-25 07:56:02
问题 Following is my table design: CREATE TABLE "x"."y"( "z" timestamp NOT NULL, "a" Timestamp NOT NULL DEFAULT z + 18 months, ) WITH (OIDS=FALSE) ; How do I specify the default value of 'a'? Can I specify this at the time of the table creation? 回答1: As postgresql documentation states The DEFAULT clause assigns a default data value for the column whose column definition it appears within. The value is any variable-free expression ( subqueries and cross-references to other columns in the current

Default argument value from overridden method (preventing boilerplate)

戏子无情 提交于 2019-12-25 05:26:34
问题 I have a base class Base and two sub classes Foo and Bar . In Base I define a function with an optional argument. This argument is either given or fetched at runtime (not at definition time). The argument is always fetched in the same exact way, which leads to subclasses having a boilerplate line of code (sure it's one line, but it's just an example). Normally this would look like this: class Base(object): def greet(self, name=None): pass class Foo(Base): def greet(self, name=None): name =

DB2: How to get generated always as statement to work with session user

好久不见. 提交于 2019-12-25 04:20:52
问题 I need to get a userstamp into a table and have not managed to figure out how the GENERATED FOR EACH ROW ON UPDATE AS statement works with the SESSION_USER variable in DB2 10.5 (LUW). Managed to get an implementation working using a function which has a fake variable for forcing the evaluation in update statements: CREATE OR REPLACE FUNCTION XXX.CURRENT_USER( tmp varchar(128)) SPECIFIC xxx.XXX_CURRENT_USER RETURNS VARCHAR(128) CONTAINS SQL DETERMINISTIC NO EXTERNAL ACTION BEGIN RETURN session

DB2: How to get generated always as statement to work with session user

天涯浪子 提交于 2019-12-25 04:20:06
问题 I need to get a userstamp into a table and have not managed to figure out how the GENERATED FOR EACH ROW ON UPDATE AS statement works with the SESSION_USER variable in DB2 10.5 (LUW). Managed to get an implementation working using a function which has a fake variable for forcing the evaluation in update statements: CREATE OR REPLACE FUNCTION XXX.CURRENT_USER( tmp varchar(128)) SPECIFIC xxx.XXX_CURRENT_USER RETURNS VARCHAR(128) CONTAINS SQL DETERMINISTIC NO EXTERNAL ACTION BEGIN RETURN session