many-to-many

Django Many to Many in template

This is my template tag in a forloop {{ product.feature_set.all.1.value }} i want to change the number 1 to the forloop.counter. is this posible? like: {{ product.feature_set.all.forloop.counter.value }} It does not work like that, but is there a way to do this? ...

Is it possible to have multiple composite (aka "many-to-many", ManyToMany) joins that don't make the result set huge.

Situation: Table book is associated with one or more authors via the _author_book table. It is also associated with one or more genres via the _book_genre table. When selecting all the books, and all their genres, and all their authors, the number of rows returned is (assume each book has at least one genre and author): PROBLEM: book...

Displaying reverse many-to-many in Django Templates

I'm in the midst of creating an alarm/notification system for a small Sales CRM app. I have a Lead_Contact model that is used to store a client's name, address, etc. as well as a Contact_Notifier models that is being used to keep track of when a client was first contacted, the last contact, and when we are going to next contact them. F...

Django: Validation on a Many-to-Many Through model

I have the following models (simplified example): class Book(models.Model): users = models.ManyToManyField(User, through=Permission) class Permission(models.Model): user = models.ForeignKey(User) role = models.ForeignKey(Group) active = models.BooleanField() book = models.ForeignKey(Book) What I need is that for a Book instance ...

Hibernate, many-to-many save causing ConstraintViolationException

Hi all, I have an object (User) which has none or many Tags. Any User can have any number of Tags, so there's a join table, user_tags which has a user_id and tag_id field. In User.hbm.xml, this is mapped as: <set name="Tags" table="user_tags"> <key column="user_id"/> <many-to-many column="tag_id" unique...

NHibernate.Linq count throws NHibernate.QueryException : could not resolve property

I'm building an ecommerce site using S#arp Architecture. I'm trying to map a hierachy of categories and retrieve the top level categories. I'm using NHibernate.Linq for this. I have the following entity: public class Category : Entity { #region Properties [DomainSignature] [NotNullNotEmpty] public virtual string Name {...

Help with querying a many to many table in mysql

I am trying to get a list of product id's that do not have certain colors (database is mysql) Here are my tables: product +------------+-------------+ | product_id | description | +------------+-------------+ | 1 | Widget 1 | | 2 | Widget 2 | | 3 | Widget 3 | | 4 | Widget 4 | | 5...

managing ManyToManyField to itself in Django

Hi! I have the following model: class MyUser(User): # some fields... contact = models.ManyToManyField("self", through='Contact', symmetrical=False, related_name="contact_set" ) class Contact(models.Model): user1 = models.ForeignKey( MyUser, related_name="contact_set1") user2 = models.ForeignKey( MyUser, related_name="...

Storage of different data formats in Rails dynamically defined by admin

I'm facing a problem where I cannot permanently decide which columns one of my models will have. A use case will be this: An admin creates a new dataset, he wants users to answer. In the dataset the admin defines several data points of different format and units. I could imagine the classes to look similar to this: class Dataset < ...

NHibernate many-to-many mapping to existing objects

I'm having some issues with a many-to-many relationship I am trying to create. The goal is to save a customer and which products they are allowed to purchase. The products are not unique to a customer and will ALWAYS exist in the database before we try to associate a customer to them. My mapping for the association currently looks lik...

Implementation of many-to-many for Sqlite in C#

I have such database on SQLite: CREATE TABLE [ArtTag] ( [article_id] integer NOT NULL, [tag_id] integer NOT NULL, CONSTRAINT [FK_ArtTag_article_id_Articles_id] FOREIGN KEY ([article_id]) REFERENCES [Articles] ([id]), CONSTRAINT [FK_ArtTag_tag_id_Tags_id] FOREIGN KEY ([tag_id]) REFERENCES [Tags] ([id]) ); CREATE TABLE [A...

Do Django ManyToManyManagers cache their data?

Basic model breakdown: Movie and MovieGenre models. The Movie model has a field called genres, which is declared as: genres = models.ManyToManyField(MovieGenre, blank=True) Here is the issue: In [42]: frank = Movie.objects.get(id=122) In [43]: frank.genres.count() Out[43]: 2 In [44]: frank.genres.all() Out[44]: [<MovieGenre: Conc...

Django select objects with empty ManyToManyField

Considering the following models, knowing a family, how do I select Kids with no buyers? class Family... class Kid(models.Model): name = models.CharField(max_length=255) family = models.ForeignKey(Family) buyer = models.ManyToManyField(Buyer, blank=True, null=True) family = get_object_or_404(Family, pk=1) for_sale = family...

Django: Display many-to-many fields in the change list

Django doesn't support displaying of related objects from a many-to-many relation in the changelist for a good reason. It would result in a lot of database hits. But sometimes it is inevitable and necessary to e.g. display an object's categories, which have a many-to-many relation to the object, in the changelist. Given that case, does ...

Nhibernate criteria API for many-to-many

My object model is the following: Item has many Tags and a Tag could belong to many Items I'd like to execte the following query using criteria's. SELECT * FROM Item item where item.Id in (Select it.ItemId from dbo.ItemToTags it where it.Tag_id = 'ONE') and item.Id in (Select it.ItemId from dbo.ItemToTags it where it.Tag_id = 'TWO') ...

Django - What's a good way to handle manytomany with intermediary table in forms and views

Suppose I have the following models - class Item(models.Model): name = models.CharField(max_length=150) value = models.DecimalField(max_digits=12,decimal_places=2) class Organization(models.Model): name = models.CharField(max_length=150) items = models.ManyToManyField(Item, through='Customizable') class Customizable(m...

Sorting rows by count of a many-to-many associated record

I know there are a lot of other SO entries that seem like this one, but I haven't found one that actually answers my question so hopefully one of you can either answer it or point me to another SO question that is related. Basically, I have the following query that returns Venues that have any CheckIns that contain the searched Keyword ...

Creating a many-to-many relation between an entity and an another many-to-many relation with (N)Hibernate

I'm trying to create a many-to-many association between an entity and another many-to-many association. How can that be done? I followed the Customer/Order/Product example to attach custom properties to a many-to-many association between two of my entities (Categories and Tags). That worked like a charm. The problem is that now I need ...

SQL table design help

I've taken over an application that has a SQL backend. There are multiple tables, but the two that I'm concerned about are these: QAProfile --------- ProfileID <pk> -int ProfileName SecurityGroups -varchar(max) SecurityGroups -------------- GroupID <pk> -int GroupName My issue is that the the SecurityGroups field is a comma delimit...

django-nonrel on Google App Engine - Implications of using ListField for ManyToMany

I am working on a Google App Engine application and I am relatively new at this. I have built an app already in Django and have a model using a field type of ManyToMany. I am aware that django-nonrel does not support many-to-many field types of Django. So I am considering using ListField instead. Questions: - What is the implication ...