many-to-many

How do I access the properties of a many-to-many “through” table from a django template?

孤街浪徒 提交于 2019-11-28 03:11:52
From the Django documentation... When you're only dealing with simple many-to-many relationships such as mixing and matching pizzas and toppings, a standard ManyToManyField is all you need. However, sometimes you may need to associate data with the relationship between two models. For example, consider the case of an application tracking the musical groups which musicians belong to. There is a many-to-many relationship between a person and the groups of which they are a member, so you could use a ManyToManyField to represent this relationship. However, there is a lot of detail about the

Filter ManyToMany box in Django Admin

冷暖自知 提交于 2019-11-28 02:48:29
I have a object with a many-to-many relation with another object. In the Django Admin this results in a very long list in a multiple select box. I'd like to filter the ManyToMany relation so I only fetch Categories that is available in the City that the Customer have selected. Is this possible? Will I have to create a widget for it? And if so - how do I copy the behavior from the standard ManyToMany field to it, since I would like the filter_horizontal function as well. These are my simplified models: class City(models.Model): name = models.CharField(max_length=200) class Category(models.Model

CodeIgniter Many-to-Many Relationship Management

Deadly 提交于 2019-11-28 02:21:49
问题 Can anyone point out a good many-to-many database tutorial for CodeIgniter. Just trying to work out the process of creating, and then updating a many-to-many relationship. My example uses a multi-select of values, wondering how you take care of monitoring changes on update etc. 回答1: I'd like to share what I do in my application. This is basically same with my answer in this question. After user submit, and before entering to database, I will fetch the existing data in the database into an

Filtering on many-to-many relations that fulfill a set of criteria

时光毁灭记忆、已成空白 提交于 2019-11-28 02:17:37
With the following models: class OrderOperation(models.Model): ordered_articles = models.ManyToManyField(Article, through='orders.OrderedArticle') class OrderedArticle(models.Model): order_operation = models.ForeignKey(OrderOperation) article = models.ForeignKey(Article) articles = ... # some queryset containing multiple articles If I want to find order operations containing at least one article, this works as expected: OrderOperation.objects.filter(ordered_articles__in=articles) However, if I want to find order operations with all the articles in the order, what is the correct way to do it?

JPA EventListener method not called on change to many-to-many collection?

不打扰是莪最后的温柔 提交于 2019-11-28 01:34:25
I am using JPA with Hibernate as the implementation in my Spring webapp. I use EntityListener s for auditing (Spring-data) and other notification purposes. In general it works fine. However, when changes are made to a many-to-many collection/relationship, without any other change to any field of the entities themselves , the @PostUpdate event of the EventListener s are not fired. To give a concrete example : I have a User and a Role entities, with a many-to-many relationship between them, using an underlying table. If I go to my user management GUI, and add (or remove) roles to a user, without

Many-to-Many link tables in grails (GORM) / hibernate

天大地大妈咪最大 提交于 2019-11-28 01:28:39
问题 I'm playing aroud with Grails and am finding the ORM stuff tedious because I don't fully understand what I'm doing when it comes to domain classes. I'm hoping someone can put me back on track Consider the following Test Job One:Many Hardware Used on Job Many:One Physical Hardware ...this is analogous to the classic Order, OrderLine, Product scenario seen in university DB examples I've created the following domain classes class Job { String jobName String jobDescription } class HardwareOnJob {

Many-to-Many Relationships in MySQL

僤鯓⒐⒋嵵緔 提交于 2019-11-28 01:13:40
问题 I've been reading up on foreign keys and joins recently, and have been pleasantly surprised that many of the basic concepts are things I'm already putting into practice. For example, with one project I'm currently working on, I'm organizing word lists, and have a table for the sets, like so: `words` Table `word_id` `headword` `category_id` `categories` Table `category_id` `category_name` Now, generally speaking this would be a one-to-many relationship, with several words being placed under a

Entity Framework Code First: how to map multiple self-referencing many-to-many relationships

做~自己de王妃 提交于 2019-11-28 01:05:45
I have created an entity type that has multiple collection properties that reference items of the same type. In other words, it reflects a single database table in which the rows are arbitrarily grouped, such that a row may appear in multiple groups. In the following simplified example, the Person class has Brothers and Sisters collection properties that also reference Person entities: public class Person { public Person() { Brothers = new Collection<Person>(); Sisters = new Collection<Person>(); } [Key] public string Name { get; set; } public int Age { get; set; } public virtual ICollection

Using both many-to-many and one-to-many to same entity

好久不见. 提交于 2019-11-28 00:59:07
问题 I have a many-to-many association in EF Code-First (as explained in this question), and I want to use a one-to-many to the same entity as well. The problem is EF does not produce the right database scheme. Code: public class A { public int Id { get; set; } public string Name { get; set; } public virtual ICollection<B> ObjectsOfB { get; set; } } public class B { public int Id { get; set; } public virtual A ObjectA { get; set; } public virtual ICollection<A> OtherObjectsOfA { get; set; } } When

has_many :through nested_form that can build multiple instances

北城以北 提交于 2019-11-27 23:20:19
I have the following code in my models: Class Farm < ActiveRecord::Base has_many :farm_products, :dependent => :destroy has_many :products, :through => :farm_products accepts_nested_attributes_for :farm_products end class Product < ActiveRecord::Base has_many :farm_products, :dependent => :destroy has_many :farms, :through => :farm_products end class FarmProduct < ActiveRecord::Base belongs_to :farm belongs_to :product end I have a form to create a new Farm, and I want to create farm_products along with this form. My farm_products table can not only contain foreign key fields. How can I add or