model

Is there a way to customize how the value for a custom Model Field is displayed in a template?

浪尽此生 提交于 2019-12-25 04:28:05
问题 I am storing dates as an integer field in the format YYYYMMDD, where month or day is optional. I have the following function for formatting the number: def flexibledateformat(value): import datetime, re try: value = str(int(value)) except: return None match = re.match(r'(\d{4})(\d\d)(\d\d)$',str(value)) if match: year_val, month_val, day_val = [int(v) for v in match.groups()] if day_val: return datetime.datetime.strftime(datetime.date(year_val,month_val,day_val),'%b %e, %Y') elif month_val:

Is there a way to customize how the value for a custom Model Field is displayed in a template?

空扰寡人 提交于 2019-12-25 04:28:03
问题 I am storing dates as an integer field in the format YYYYMMDD, where month or day is optional. I have the following function for formatting the number: def flexibledateformat(value): import datetime, re try: value = str(int(value)) except: return None match = re.match(r'(\d{4})(\d\d)(\d\d)$',str(value)) if match: year_val, month_val, day_val = [int(v) for v in match.groups()] if day_val: return datetime.datetime.strftime(datetime.date(year_val,month_val,day_val),'%b %e, %Y') elif month_val:

Laravel Eloquent ORM returnig stdClass instead of actual Model

喜欢而已 提交于 2019-12-25 04:19:40
问题 I'm doing $mymodel = MyModel::where( 'url', $domain )->first(); and this was returning a MyModel object and now, somehow, it is returning a stdClass. What's happening? Is it some update on the laravel? Have I changed something? Thanks 回答1: Found the problem. I did updated the laravel today and it was updating to a dev version. By being dev it could have bugs and it did. I just rollback to version "4.1.22" and it's working fine. 回答2: I ran into the exact same issue yesterday. But just updated

Get default zend db adapter in table model

岁酱吖の 提交于 2019-12-25 03:59:34
问题 How can I get the default db adabter in my table model? I want to use it to create a transaction. In database.global.php: return array( 'service_manager' => array( 'factories' => array( 'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory', ), 'aliases' => array( 'db' => 'Zend\Db\Adapter\Adapter', ), ), 'db' => array( 'driver' => 'Pdo', 'dsn' => 'mysql:dbname=cww;host=localhost', 'driver_options' => array( PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'' ), ), ); Now I

Global model base url and optional automapping

可紊 提交于 2019-12-25 03:42:19
问题 Is there a way to set a global api_root attribute instead of repeating the declaration over and over in the codebase? So instead of: var UserModel = Backbone.Model.extend({ urlRoot: '/user', defaults: { name: '', email: '' } }); var user = new UserModel(); user.save(userDetails, { success: function (user) { alert(user.toJSON()); } }); I could have set an app-wide attribute like: app.api_root = 'https://api.ltmo.com/'; And then just map according to convention: var UserModel = Backbone.Model

Using constant for defining property format in MVC

吃可爱长大的小学妹 提交于 2019-12-25 03:34:39
问题 In my MVC application I have many properties of DateTime datatype and I define DataFormatString on every new property in this datatype is defined as below: Model: [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)] public DateTime StartDate{ get; set; } [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)] public DateTime EndDate{ get; set; } Instead of this, I think there is another option to define these DataFormatStrings for just

Yii2: How to let ActiveRecord models only see certain database data?

99封情书 提交于 2019-12-25 03:07:49
问题 I'm trying to implement a multi-tenant application. I have different customers that are using the same code. But each customer gets its own entry script with its own configuration. The customer id is accessible by Yii::$app->params['customerId'] . Note: I have to distinguish the customers that way because there is no login/authentication. Anyway, assume the controller action is called and a customer id is given with the parameter. Now I have some tables and each has a column for the customer

How to customize a Django ModelForm

不打扰是莪最后的温柔 提交于 2019-12-25 02:53:45
问题 I want to build a form based on my customer model. In the form, the logged-in user specifies the payee, types in an amount and selects the account he wants to pay from. This is the model and the form thus far: class Payment(models.Model): payee = models.ForeignKey(Customer) amount = models.IntegerField() accounts = models.ManyToManyField(BankAccount) class PaymentForm(forms.ModelForm): class Meta: model = Customer widgets = { 'accounts': forms.CheckboxSelectMultiple(), } The problem with this

accessing MVC model with in java script

社会主义新天地 提交于 2019-12-25 02:30:02
问题 Is there a way i can access model from with in java script? ... if yes then how? I have a Model with folowing properties and i want to set few of them to variable within java script public class BillPaymentModel { public string ClassName = "BillPaymentModel"; public BillDTO BillDTOObj { get; set; } public DebitablesDTO SelectedAccount { get; set; } public CreditablesDTO SelectedCreditCard { get; set; } public ExecutionSchedulingDTO ExecSchedDTO = new ExecutionSchedulingDTO(); public string

Dynamic data validation in ASP.NET MVC

随声附和 提交于 2019-12-25 01:33:25
问题 I've recently read about the model validation capabilities of ASP.NET MVC which are all very cool until a certain point. What happens if the application doesn't know the data that it works with because it is all stored in DB and built together at runtime. Just like in Drupal, I'd like to be able to define custom types at runtime, and assign runtime validation rules as well. Obviously, the idea of assigning attributes to well established models is now gone. What else could be done ? I am