FAQ Database Discussion Community


Variable has different values inside and outside a function

javascript,function,models
I'm trying to set the value of an ID in the variable newID. To "fill" the variable I'm reading a model like this: press: function() { var newID = 0; oModel.read("/Delivery", null, null, true, function(oData) { newID = oData.results[oData.results.length - 1].ID; console.log(newID); } console.log(newID); } The first console.log gives me...

How to separate the model into two applications

python,django,django-models,models
I have one application and one model. I want to separate the model on two applications, so that the user was managed from a separate application. Is the transfer of this model will do the trick? What I have to do? class User(AbstractUser): country = models.CharField(max_length=2, choices=COUNTRY, default=RUSSIA) Here is...

How can I save an empty model (I only need it's pk created)

python,django,models
I have these models: class Storage(models.Model): id = models.AutoField(primary_key=True) def __unicode__(self): return str(self.id) class StorageType(models.Model): tripa = 'Tripa' portada = 'Portada' type_choice = ( (tripa, 'Tripa'), (portada, 'Portada'), ) sto_type = models.CharField(max_length=9, choices=type_choice, default=tripa) storage = models.ForeignKey(Storage) paper_type = models.ForeignKey(Paper) paper_qnty = models.IntegerField(blank=True, default=0) web_paper_qnty = models.IntegerField(blank=True, default=0) def...

NameError: name 'Usuario' is not defined

python,django,migration,models
I have this error in django when i try to do "makemigrations" Code: from django.db import models from django.contrib.auth.models import User # Create your models here. class Usuario(models.Model): user = models.OneToOneField(User) amigos = models.ManyToManyField(Amigo) class Amigo(models.Model): usuarios = models.ForeignKey(Usuario) class Regalo(models.Model): nombre = models.CharField(max_length=100) enlace_compra = models.CharField(max_length=200) amigo_encargado = models.OneToOneField(User)...

laravel work safely with mass assignments

php,laravel,eloquent,models,laravel-5
I set my laravel models guarded array attribute, now of course I can't set Model::create(['gaurded_field' => 'value']); But how can I insert it safely, only option that comes to mind is to create first, then do: $model_object = Model::create(['other_attributes' => 'other_values']); $model_object->gaurded_field = 'value'; $model_object->save(); but that just requires 2...

A query to search on the whole model [Laravel]

jquery,sql,laravel,models
I want some query to search on all of [User] Model for example !! That I can give it an input and search for it on all User's columns .. is there some thing like that ? ...

Connecting two models belongs_to/has_many and selecting via dropdown in form

ruby-on-rails,key,models,rails-models
I am rails beginner and I am facing a basic problem. I have found a couple of solutions but none of them fully describe my problem. I have two models: Contact and Group Group has_many :contacts Contact belongs_to :group (Through devise there is a third user model) When creating a...

Review model - shared across two different other models

ruby-on-rails,associations,models
I am making an application that lets people list food items that they want to sell. They list Dishes (Dish model) and when people buy it, an Order record is created. I want people to be able to submit reviews on Dishes if they have purchased it, and also review...

Pattern to organize related items into groups

python,django,models
Let me try to explain what I want to achieve by a small example application. It is a shopping list application that lets you add predefined Items to your ShoppingList as Groceries. The smart thing would be that every Item is related to a Store. When I am done adding...

Web api: Retrieve m2m model vs Retrieve main model

design,views,models,m2m
I have a code-design question. Lets say we have a web app with a web service (rest api) and the models User, Job and also JobFavorite. JobFavorite model is a m2m model with fields user and job, meaning that a user can mark a job as favorite. Lets say that...

get call stack for Model Classes in Django

python,django,django-models,models
In Django, I would like to get call stacks of classes in Model; on call, and log them. The Django Model uses QuerySet API to access objects of the Model class. Say, we have defined Model class Abc, and it is called by other django apps using QuerySet API. For...

Why a virtual property getter should not be called in cakePHP 3?

cakephp,models,cakephp-3.0
in a ctp, I display several virtual properties from 2 entities, computed by getters. It's ok for one of the both entities but for the other, none of the properties getters are never called. Here is an excerpt of the ctp: <table> .... <td><?= $agTheme->agthemelanguages_wc_string ?></td> <td><?= $agPoi->paragraph_length_string ?></td> <td><?=...

Adding FieldFile objects without form in django

python,django,models
I have a django model as follow: class XML(ExtensibleModel): xml = models.FileField(upload_to='xml',blank=True, null=True) Here, I store some xmls files. Before, I submited the files to my server by a html form. Now, I copy the files by ssh, and I want to keep storing the new files in this model....

how to display articles by user in django?

django,user,views,models
I have article models: class Article(models.Model): title = models.CharField(max_length=200) body = models.TextField() pub_date = models.DateTimeField(editable=False) modified = models.DateTimeField(editable=True) whopost = models.ForeignKey(UserProfile) and I have userprofile models: class UserProfile(models.Model): user = models.OneToOneField(User) info1 = models.BooleanField(default=False) mobile = models.CharField(max_length=50,default="") I try to do a relation between a user and article so I...

How do I reference multiple models in flask?

flask,models
How do I handle and reference multiple models in a Flask application? Is there any reason I cannot have more than one model class, .py files? Instead of one big models.py, is there a way to have the following in flask: Example models: students.py teachers.py classes.py schedules.py ... ?...

Best way of protecting the show() method against users accessing other users messages

laravel,laravel-4,routing,models,relationships
Ok, so I have a basic messaging system, I have a relationship set up so I can just call $user->messages to retrieve an array of the users inbox messages. I also have a very simple show method that currently only grabs the message with id passed to the show() function....

Android coustom Listview is not showing

android,listview,android-listview,models
UserInfo model have three fields name,email,photo but want to show only name on the listview. when user click on listview then get all fields like name,photo email Also want to set filter in listview My Listview Adapter class public class UsersAdapter extends ArrayAdapter<UserInfo> { ArrayList<UserInfo> users; Context context; LayoutInflater inflater;...

Can not reach to associated models from Jquery

javascript,jquery,ruby-on-rails,controller,models
I have associated models. Boat & Location Model. I am trying to reach to Boat Model from Jquery code but I could not do it. The thing; I return all the locations to Jquery as listing and it contains address, boat_id etc. So listing.address works, listing.boat_id works but listing.boat.year (for...

Rails: Select from multiple models

ruby-on-rails,ruby,ruby-on-rails-4,activerecord,models
In my rails application i a have a job model belongs_to :company belongs_to :organization and i want to drop-down a name list of all company name and organization name in the same field so I'm wondering if this is possible actually I was just using company name before i have...

Strange has_many Association Behavior in Rails 4

ruby-on-rails,ruby,ruby-on-rails-4,models
I've got two tables, User and Allergy. These are connected via another table, UserAllergy. The models are as would be expected: class User has_many :user_allergies has_many :allergies, through: :user_allergies end class UserAllergy belongs_to :user belongs_to :allergy end class Allergy has_many :user_allergies has_many :users, through :user_allergies end What I'm confused about...

How to obtain different type of collections for the same Model in an Association in Rails 4?

ruby-on-rails,ruby,rails-activerecord,models,model-associations
In my application I have a User model and a Job model. Users can post many jobs, and other users can apply to these jobs by posting proposals. The job poster can then select a user from the list of users who have applied, later this user will be assigned...

How to change upload_to parameter of ImageField based on field name in Django?

django,models,filefield,imagefield
I would like to upload images to the media root based on the field values given by the Django admin user. Here is the code that I've written and I know that the upload_to parameter is causing the problem. But I don't know how to make it work. models.py class...

sails.js: Lifecycle callbacks for Models: Do they support beforeFind and afterFind?

sails.js,models,waterline
In sails.js, Models support lifecycle callbacks for validate, create, update and destroy. Is there support for callbacks for find() or query as well? Like beforeFind() and afterFind()? The idea is same. I would want to validate / modify parameters before the query is run or after the query is run....

Extending a package model

php,laravel-4,models,extends,extending-classes
I have installed Cmgmyr\Messenger, however, I need to extend the Thread model and potentially a couple of the others as my users table does not contain a name field. The method I need to extend is: /** * Generates a string of participant information * * @param null $userId *...

Getting error when trying to insert a record that has composite primary keys

php,sql,laravel,models
I have a Many-to-Many relation, so the implementation require to create new table with two primary keys ,, here's the new table : public function up() { Schema::create('friendship', function(Blueprint $table) { $table->integer('user1_id')->index('fk_user_has_user_user1_idx'); $table->integer('user2_id')->index('fk_user_has_user_user2_idx'); $table->boolean('state')->nullable(); $table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'));...

Efficient reverse of queryset

python,django,django-queryset,models
I'm trying to look at the most efficient way to traverse my models to get the data that I'm after. I have three "related" models. Item, ProtectionList and Player Protection List class ProtectionList(models.Model): player = models.ForeignKey(Player) main_hand = models.ForeignKey(Item, null=True, blank=True, related_name='main_hand') off_hand = models.ForeignKey(Item, null=True, blank=True, related_name='off_hand') head =...

Order parent model using children in rails

ruby-on-rails,order,models
I have model product and vote, I need to order products by votes count DESC. product has_many :votes, vote belongs_to :product index_controller.rb def index @products = Product.all end ...

Best way to store category and subcategories of an item in Django models

python,django,database,models
I want to store something like an Apple which will be stored as "Tree Fruit - Apple - Fuji - Organic" while there will be some items with more categories like Wheat which is "Cereal Grain - Wheat - Soft White Winter - Stephens - Organic". class Item(models.Model): user =...

Why is foreign_key ignored?

ruby-on-rails,ruby,associations,models
I have 2 models with has_one and has_many associations. realm.rb class Realm < ActiveRecord::Base has_one :realm_type, foreign_key: "id" end realm_type.rb class RealmType < ActiveRecord::Base has_many :realms, foreign_key: "realm_type_id" end But when i preforming sql request Realm.find(1).realm_type in rails console, i get Realm Load (0.3ms) SELECT "realms".* FROM "realms" WHERE "realms"."id"...

Model.objects.get returns nothing

python,django,object,get,models
I'm having this weird problem when using Model.objects.get(op1=1,op2=2) it raises the does not exist error although it exists. Did that ever happen with anyone? I even checked in my logs to make sure that the log happened when the id already existed in the database. [2015-04-24 20:18:21,106] ERROR: Couldn't find...

Angular variables not updating outside loop

javascript,angularjs,loops,angularjs-scope,models
So I'm running into a weird issue with Angular where I created a raw predefined object to loop through card stats for a card game I am working on. $scope.attack = 500; $scope.defense = 500; $scope.cardPowers = [ { name: "balanced", attack: 2500, defense: 1500, cost: 3 }, { name:...

Django: Creating editable default values for model instance based on foreignkey existance

python,django,database,models
I'm playing around in Django, and wondering if there is a way to loop through instances of two different models I have created? / models.py: class Tran(models.Model): name = models.CharField(max_length=300) description = models.CharField(max_length=2000) type = models.ForeignKey(TransactionType) def __str__(self): return self.name class DocLink(models.Model): trann = models.ForeignKey(Transaction) t_link = models.CharField(max_length=2000) t_display =...

Java 3D LWJGL collision

java,lwjgl,models,collision,detection
I am making a 3D Java game with the LWJGL library, and I was wondering how to add collision detection, so that the player does not go through models. I am using OBJ models. Here is the OBJLoader class, which loads the models: package renderEngine; import java.io.BufferedReader; import java.io.File; import...

Django - how to create duplicate apps without duplicating the code (models, signals and so on)

django,models
This may be a weird question, and from the title it may not be obvious, but couldn't find out a better / more descriptive title for my questions. I have an inventory control app, with own models, signals, admin, and forms. I need to duplicate this app for multiple companies,...

Yii2 custom validator not working as guide suggests

validation,module,yii2,models,yii2-advanced-app
I've searched around here for some time today, but I'm unable to understand why my validators aren't working in my model. I have a Module with a model "Page" in my code below. I have 2 attributes that I need to use to validate the model. They are hero_link and...

Django - Use class as inline in both parent and parent of parent

django,django-admin,inline,models
I have three class in my code. Exam, Question and QuestionResource. QuestionResource is a file and has a foreign key to Question.Also Question has a foreign key to Exam. Currently Question is included as inline in Exam's admin view. However it is seperately registered in the admin so I can...

upload_to dynamically generated url to callable

python,django,models
I've seen a lot of post about this problem without really understanding how to solve it. I have this model: class Project(TimeStampedModel): name = models.TextField(max_length=100, default='no name') logo = models.ImageField() I'd like to have my image saved to media root following this template: <name>/logo/<filename> At first glance, I would like...

Rails modeling headache

ruby-on-rails,oop,models
I am in the process of building a Rails app that will let logged-in users: create multiple agendas access each agenda through a "month" view add events to each month share each agenda (through a link) with other logged-in users, who will see it with the same default "month" view...