model

Required field in Django model not mandatory?

大城市里の小女人 提交于 2020-08-07 06:17:39
问题 I have the following Django model: class Customer(models.Model): email = models.EmailField(unique=True) In my testcase, I instantiate it without an e-mail. class CustomerTestCase(TestCase): def test_that_customer_can_be_created_with_minimum_data(self): customer = Customer.objects.create() print(customer.__dict__) I expect it to raise an error, but it creates a record with an empty field email . The same thing happens if I explicitly say null=False and blank=False . Instead, it just prints the

Rails HABTM setup, model object, & join_table insertion controller setup

♀尐吖头ヾ 提交于 2020-08-06 05:46:28
问题 I have the following setup. 1 product has many product_types. many product_types have 1 type. A HABTM relationship from my understanding of the docs. My models are class Product < ApplicationRecord has_and_belongs_to_many :types end class Type < ApplicationRecord has_and_belongs_to_many :products end I have a join table migration as such class CreateJoinTableProductTypes < ActiveRecord::Migration[5.1] def change create_join_table :products, :types do |t| t.index :product_id t.index :type_id

How to stop embed video in Model Popup in Javascript (WooCommerce)?

╄→гoц情女王★ 提交于 2020-07-30 11:45:34
问题 UPDATED I have used javascript to create a popup and it's working fine. The issue is that i am using iframe embed video code (Facebook) in the model. the model is working fine and on pressing cross button the popup diappears. but the issue is that when used opens popup and play video and then press cross button the video continues to play. The video must stop on pressing cross button. the popup is disappearing but the video plays in background. Another issue is that the FEATURED VIDEO BUTTON

How to stop embed video in Model Popup in Javascript (WooCommerce)?

孤街浪徒 提交于 2020-07-30 11:44:50
问题 UPDATED I have used javascript to create a popup and it's working fine. The issue is that i am using iframe embed video code (Facebook) in the model. the model is working fine and on pressing cross button the popup diappears. but the issue is that when used opens popup and play video and then press cross button the video continues to play. The video must stop on pressing cross button. the popup is disappearing but the video plays in background. Another issue is that the FEATURED VIDEO BUTTON

C# - Retrieve data from persistence storage and save it to the view model

泄露秘密 提交于 2020-07-16 09:32:28
问题 Hello I have a controller method that I want to return the view model of that looks like this This is what it would look like if it was hard-coded public ActionResult SpecialOrderSummary(int? id) { // Retrieve data from persistence storage and save it to the view model. // But here I am just faking it. var vm = new ItemViewModel { ItemId = 123, ItemName = "Fake Item", Parts = new List<ItemPartViewModel> { new ItemPartViewModel { PartId = 1, PartName = "Part 1" }, new ItemPartViewModel {

C# - Retrieve data from persistence storage and save it to the view model

喜你入骨 提交于 2020-07-16 09:32:13
问题 Hello I have a controller method that I want to return the view model of that looks like this This is what it would look like if it was hard-coded public ActionResult SpecialOrderSummary(int? id) { // Retrieve data from persistence storage and save it to the view model. // But here I am just faking it. var vm = new ItemViewModel { ItemId = 123, ItemName = "Fake Item", Parts = new List<ItemPartViewModel> { new ItemPartViewModel { PartId = 1, PartName = "Part 1" }, new ItemPartViewModel {

Django - Display “Model Object” in the admin page instead of Object title

女生的网名这么多〃 提交于 2020-07-03 07:06:06
问题 As displayed in the image it displays "Lecture Object" instead of the Lecture's title. As I've understood it, unicode should take care of this, but it doesn't seem to here. Here is my unicode method: def __unicode__(self): return self.title 回答1: To display a custom string as your Model's object representation, you should: In Python 2.x def __unicode__(self): return self.some_attr # What you want to show In Python 3.x def __str__(self): return self.some_attr # What you want to show 来源: https:/

Database Model's meta data should be defined in models file or migration file?

巧了我就是萌 提交于 2020-06-28 06:57:11
问题 Using sequelize init I generated a model with a migration. Inside model.js there is only the definition of the type of each attribute, e.g. const User = sequelize.define('User', { firstName: DataTypes.STRING, lastName: DataTypes.STRING, email: DataTypes.STRING, password: DataTypes.STRING }, {}); In migration file, there are additional options e.g. ... up: (queryInterface, Sequelize) => { return queryInterface.createTable('Users', { id: { allowNull: false, autoIncrement: true, primaryKey: true

Select specific fields in Django get_object_or_404

不问归期 提交于 2020-06-27 13:08:44
问题 I have a model in Django with too many fields. Ex: class MyModel(models.Model): param_1 = models.CharField(max_length=100) ... param_25 = models.CharField(max_length=100) Now I need to get the detail view based on an id. I have seen may methods like, obj = MyModel.objects.get(pk=5) obj = MyModel.objects.filter(pk=5)[0] obj = get_object_or_404(MyModel, pk=1) The last method suits the best as I can provide a 404 error without any code change. But I need only param_1 and param_2. Hence I need a

Django - import model from another project

一个人想着一个人 提交于 2020-06-25 21:38:39
问题 I've never done such thing so i'm not sure what would be the best approach for solving this problem: I have two Django projects: root/ project1/ manage.py project1/ models.py urls.py ... project2/ manage.py project2/ models.py urls.py ... Those projects use same database, they have around 10 models (database tables) each and some of the models overlap: Project1 needs ForeignKey from one fo the Project2's models, but also Project2 needs ForeignKey from one of the Project1's models: Project1: