m2m

Django m2m queries, distinct Users for a m2m relationship of a Model

Hi, I have a model Model with a m2m field : user = .. fk user ... watchers = models.ManyToManyField(User, related_name="boardShot_watchers", null=True) How do i select all distinct Users involved in this watchers relationship for all my entries of type Model ? I dont think there is an ORM way to access to intermediary M2M tabl...

Is it possible to subclass a django model used in a many2many though relation?

Hi there, I was wondering whether it was possible to subclass a model used as the intermediate model in a M2M relation - and then display it through the usual ModelInline procedure... The code will explain it better (in models.py): from django.db import models from django.contrib import admin #the many2many_through model first class...

Editing both sides of M2M in Admin Page

Hello all, First I'll lay out what I'm trying to achieve in case there's a different way to go about it! I want to be able to edit both sides of an M2M relationship (preferably on the admin page although if needs be it could be on a normal page) using any of the multi select interfaces. The problem obviously comes with the reverse sid...

Django Forms save_m2m

Hi I have a model which has 2 many to many fields in it. one is a standard m2m field which does not use any through tables whereas the other is a bit more complecated and has a through table. I am using the Django forms.modelform to display and save the forms. The code I have to save the form is if form.is_valid(): f = form....

Applied security

Background Terminals are a compination of hardware and software. Terminal's main responsibility is to - collect data (with it's sensors) - process and transmit collected data to data server over the Internet. The terminal has Internet access either via WLAN or GPRS. Terminal are running embedded Linux. Things to consider, security pe...

Django: accessing ManyToManyField objects after the save [Solved]

This is baffling me... When I save my model, the book objects are unchanged. But if I open the invoice and save it again, the changes are made. What am I doing wrong? class Invoice(models.Model): ... books = models.ManyToManyField(Book,blank=True,null=True) ... def save(self, *args, **kwargs): super(Invoice, sel...

Edit the opposite side of a many to many relationship with django generic form

I have two models: class Actor(models.Model): name = models.CharField(max_length=30, unique = True) event = models.ManyToManyField(Event, blank=True, null=True) class Event(models.Model): name = models.CharField(max_length=30, unique = True) long_description = models.TextField(blank=True, null=True) In a previou...

How to get the related_name of a many-to-many-field?

I'm trying to get the related_name of a many-to-many-field. The m2m-field is located betweeen the models "Group" and "Lection" and is defined in the group-model as following: lections = models.ManyToManyField(Lection, blank=True) The field looks like this: <django.db.models.fields.related.ManyToManyField object at 0x012AD690> T...

Django m2m form appearing fields

I have a classroom application,and a follow relation. Users can follow each other and can create classrooms.When a user creates a classroom, he can invite only the people that are following him. The Classroom model is a m2m to User table. i have in models. py: class Classroom(models.Model): creator = models.ForeignKey(User) c...

Django m2m adding field in the secondary table

I have a model in wich i'm using m2m Django ORM feature, in order to create an aditional table to hold my 'classrom members'. My problem is: the membership to a classroom must be accepted by the invited one, so i need a boolean field :1=accepted, 0=refused/unseen yet. How can i include this boolean variable in the aditionally generated c...

django m2m how can i get m2m table elements in a view

i have a model using m2m feature: class Classroom(models.Model): user = models.ForeignKey(User, related_name = 'classroom_creator') classname = models.CharField(max_length=140, unique = True) date = models.DateTimeField(auto_now=True) open_class = models.BooleanField(default=True) members = models.ManyToManyFiel...

django display m2m elements in a template

if a have a declaration like def inside_classroom(request,classname): theclass = Classroom.objects.get(classname = classname) members = theclass.members.all() c = Courses.objects.filter(classroom = theclass) return render_to_response('classroom/inside_classroom.html', { 'theclass': theclass, 'c':c, 'members':mem...

django m2m form save " through " table

i'm having trouble in saving a m2m data, containing a 'through' class table. I want to save all selected members (selected in the form) in the through table. But i don't know how to initialise the 'through' table in the view. my code: class Classroom(models.Model): user = models.ForeignKey(User, related_name = 'classroom_creator')...

django Cannot set values on a ManyToManyField which specifies an intermediary model. Use Manager instead

i am working on saving on the same form two tables - having a m2m relation. I don't succeed, my error persists with something like: Cannot set values on a ManyToManyField which specifies an intermediary model. Use Membership's Manager instead where Membership is my 'through table'. my code : def save_classroom(request): classroom_...

Django Admin - Displaying Intermediary Fields for M2M Models

Hi, We have a Django app which contains a list of newspaper articles. Each article has a m2m relationship with both a "spokesperson", as well as a "firm" (company mentioned in the article). At the moment, the Add Article page for creating new Articles is quite close to what we want - it's just the stock Django Admin, and we're using fi...

Django save a list of items in a m2m intermediary table

I have a m2m field in a class, and a through table. I am not table to save the list of items from the through table. if i have a multi select form, like below, and i want to be able to save all the selected items, how should i do it?? My model form looks like this: class ClassroomForm(ModelForm): class Meta: model = Class...

Define ManyToMany relation in another application in Django.

I have apps Users and Projects and would like to define another app called Roles for extending django-auth for per-project basis. I defined ProjectMembership in the Roles app as a custom ManyToMany relationship model. But how can I define the M2M field in User or Project model with through declaration? So question is can we define mode...

Django cannot make m2m_changed change the same m2m field

My models looks something like this: class Store: category = ManyToManyField(Category) class Category: parent = ForeignKey(Category) This is what I want to do: def update_storem2m_handler(instance, action, reverse=False, pk_set=[], **kwargs): for c in instance.category.all(): instance.category.add(c.parent) m2m_ch...

copy all fields of a django model instance

Hello everybody, ok i think this is very basic, but since i'm new to django i don't know how to handle this.. I need to copy an instance of a django-model. As explained here, there is a problem with copying many2many relations. But the attachment "django-model-copying.diff" has that function i guess. So i don't know - does my django alr...

IntegrityError with Django m2m relations

I have a relatively simple Django app, with quite heavy usage that is responsible for quite some concurrency in the db operations. I have a model Post with a m2m to a Tag model. A single line in my code, p.add(t) is repeatedly causing mysql exceptions (where p is a Post instance and t is a Tag instance.) IntegrityError: (1062, "Dupli...