m2m

Django Tastypie not Updating Resource with ManyToManyField

孤街醉人 提交于 2019-11-28 02:26:51
问题 Why doesn't my resource with a ManyToManyField update with this PUT request? curl --dump-header - -H "Content-Type: application/json" -X PUT --data '{"uuid":"blah","pass_token":"blah","favorites": ["/api/v1/organizations/1/"]}' http://localhost:8000/api/v1/devices/2/ I get this response: HTTP/1.0 400 BAD REQUEST Date: Wed, 11 Jul 2012 22:21:15 GMT Server: WSGIServer/0.1 Python/2.7.2 Content-Type: application/json; charset=utf-8 {"favorites": ["\"/api/v1/organizations/1/\" is not a valid value

Django: cannot detect changes on many-to-many field with m2m_changed signal - auditing at model-level

时间秒杀一切 提交于 2019-11-27 21:55:24
问题 I'd like to keep track on what field has changed on any model (i.e. audit at model level since it's more atomic, not at admin/form-level like what django and django-reversion can already do). I'm able to do that for any field using pre/post save/delete signals. However, I have a problem of doing that on an m2m field. For the code sample below, i define 'custom_groups' m2m field in user change form since it's a reverse relation. When user saves the form on admin interface for example, I'd like

CRM点击多选框——第23天

情到浓时终转凉″ 提交于 2019-11-27 08:49:49
在table_objs_change.html: <form class="form-horizontal" method="post" onsubmit="return SelectAllChosenData()">{% csrf_token %} <div style="color: red">{{form_obj.errors}}</div> {% for filed_form in form_obj%} <div class="form-group"> <label class="col-sm-2 control-label" style="font-weight:normal"> {% if filed_form.field.required%} <b>{{filed_form.label}}</b> {% else %} {{filed_form.label}} {% endif %} </label> <div class="col-sm-10"> {#<input type="email" id="inputEmail3" placeholder="{{filed_form}}">#} {% if filed_form.name in admin_class.filter_horizontal%} <div class="col-lg-5"> {% get_m2m

Django m2m form save “ through ” table

主宰稳场 提交于 2019-11-27 01:11:55
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') classname = models.CharField(max_length=140, unique = True) date = models.DateTimeField(auto_now=True) open_class = models.BooleanField(default=True) members = models.ManyToManyField(User,related_name="list of invited members", through = 'Membership') class

Direct assignment to the forward side of a many-to-many set is prohibited. Use emails_for_help.set() instead

时光怂恿深爱的人放手 提交于 2019-11-26 22:51:44
问题 I am new to Django and didn't find any reference regarding this issue. I am getting this error when i use many to many field in django model(models.py). i guess the issue is assining m2m filed in view(views.py) from form(forms.py). How to assign m2m field in view. Django version 2.O python 3.5 models.py class User(AbstractUser): username=models.CharField(max_length=20) email = models.EmailField(_('email address'), unique=True) class Setupuser(models.Model): organization=models.CharField(max

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

本小妞迷上赌 提交于 2019-11-26 16:36:55
问题 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_instance = Classroom() if request.method == 'POST': form = ClassroomForm(request.POST, request.FILES, user = request.user) if form.is_valid(): new_obj = form.save

Django m2m form save “ through ” table

混江龙づ霸主 提交于 2019-11-26 08:16:37
问题 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\') classname = models.CharField(max_length=140, unique = True) date = models.DateTimeField(auto_now=True) open_class = models.BooleanField(default=True)