manytomanyfield

Django: Cannot resolve keyword '' into field. Choices are:

梦想的初衷 提交于 2019-12-04 07:39:04
I am having this weird problem accessing ManyToManyField . I have following models. class Link(models.Model): title = models.CharField(max_length = 200) url = models.URLField(unique = True) tags = models.ManyToManyField(Tag) creation_date = models.DateTimeField(auto_now_add = True) user = models.ForeignKey(User) likes = models.ManyToManyField(User, related_name = "%(app_label)s_%(class)s_user_likes") dis_likes = models.ManyToManyField(User, related_name = "%(app_label)s_%(class)s_user_dis_likes") class Meta: abstract = True class URL(Link): preview_image = models.URLField() preview_heading =

Django Admin: Many-to-Many listbox doesn't show up with a through parameter

試著忘記壹切 提交于 2019-12-03 05:11:15
问题 I have the following models: class Message(models.Model): date = models.DateTimeField() user = models.ForeignKey(User) thread = models.ForeignKey('self', blank=True, null=True) ... class Forum(models.Model): name = models.CharField(max_length=24) messages = models.ManyToManyField(Message, through="Message_forum", blank=True, null=True) ... class Message_forum(models.Model): message = models.ForeignKey(Message) forum = models.ForeignKey(Forum) status = models.IntegerField() position = models

Django migration error :you cannot alter to or from M2M fields, or add or remove through= on M2M fields

醉酒当歌 提交于 2019-12-03 04:30:39
问题 I'm trying to modify a M2M field to a ForeignKey field. The command validate shows me no issues and when I run syncdb : ValueError: Cannot alter field xxx into yyy they are not compatible types (you cannot alter to or from M2M fields, or add or remove through= on M2M fields) So I can't make the migration. class InstituteStaff(Person): user = models.OneToOneField(User, blank=True, null=True) investigation_area = models.ManyToManyField(InvestigationArea, blank=True,) investigation_group =

Show a ManyToManyField as Checkboxes in Django Admin

橙三吉。 提交于 2019-12-02 22:17:51
Is there a simple way to show a ManyToManyField as Checkboxes in Django Admin?? Any suggestions? Shawn Chin From this answer it seems like it is possible to use ModelAdmin.formfield_overrides to override the ManyToManyField to use CheckBoxSelectMultiple : from django.db import models from django.contrib import admin from django.forms import CheckboxSelectMultiple class MyModelAdmin(admin.ModelAdmin): formfield_overrides = { models.ManyToManyField: {'widget': CheckboxSelectMultiple}, } I haven't tried it and am merely quoting from the source, but it seems plausible. Good luck. Warning : as

Django Admin: Many-to-Many listbox doesn't show up with a through parameter

孤人 提交于 2019-12-02 18:27:21
I have the following models: class Message(models.Model): date = models.DateTimeField() user = models.ForeignKey(User) thread = models.ForeignKey('self', blank=True, null=True) ... class Forum(models.Model): name = models.CharField(max_length=24) messages = models.ManyToManyField(Message, through="Message_forum", blank=True, null=True) ... class Message_forum(models.Model): message = models.ForeignKey(Message) forum = models.ForeignKey(Forum) status = models.IntegerField() position = models.IntegerField(blank=True, null=True) tags = models.ManyToManyField(Tag, blank=True, null=True) In the

How can I store history of ManyToManyField using django-simple-history.

时光怂恿深爱的人放手 提交于 2019-12-02 05:38:39
How can I store history of ManyToManyField using django-simple-history. I used HistoricalRecords with attribute m2m_filds but it is throwing error: unexpected keyword argument 'm2m_fields' I'm macro1 on GitHub, and I guess de facto maintainer of django-simple-history. From your question it seems that you're just asking about general ManyToManyField support compared with other fields. The short answer is that we do not currently support it. ManyToManyFields actually create an in-between model that represents the relationship between the two models you're working with. If you want tracking on

count values from manytomanyfield

廉价感情. 提交于 2019-12-02 05:18:49
问题 I am trying to count the distinct values from a group of objects that have a manytomanyfield e.g. object article has manytomanyfield of tag objects one article has tags "tag1" "tag2" another article has tags "tag2" "tag3" I would like to figure out something that would return something along the lines of: "tag1": 1 "tag2": 2 "tag3": 1 I thought I could do something with articles.objects.all().values('tags') or something but I came up empty. 回答1: models.py class Topping(models.Model): name =

Django throws 'Direct assignment to the forward side of a many-to-many set is prohibited.' error

喜欢而已 提交于 2019-12-02 03:44:26
问题 I have two models in Django Users and Contexts .I have defined the models as below class User(models.Model): userId = models.PositiveIntegerField(null = False) pic = models.ImageField(upload_to=getUserImagePath,null=True) Email = models.EmailField(null = True) class Contexts(models.Model): context_name = models.CharField(max_length=50) context_description = models.TextField() context_priority = models.CharField(max_length=1) users = models.ManyToManyField(User, related_name='context_users')

Django throws 'Direct assignment to the forward side of a many-to-many set is prohibited.' error

旧时模样 提交于 2019-12-02 00:54:25
I have two models in Django Users and Contexts .I have defined the models as below class User(models.Model): userId = models.PositiveIntegerField(null = False) pic = models.ImageField(upload_to=getUserImagePath,null=True) Email = models.EmailField(null = True) class Contexts(models.Model): context_name = models.CharField(max_length=50) context_description = models.TextField() context_priority = models.CharField(max_length=1) users = models.ManyToManyField(User, related_name='context_users') Now I get a POST request which contains the below JSON { "user" : 12, "action" : "add", "context_name":

How to write migration to change primary key of model with ManyToManyField

梦想的初衷 提交于 2019-12-01 19:40:33
I have a UserProfile model that refers to my User model with a OneToOneField . I also use the post_save signal to auto create the UserProfile when the user is created. This works great apart from when creating a user through the admin (where I use an inline) when I get an error about duplicate profile. This answer recommends setting the primary key to be the OneToOneField referring to user . So before: class UserProfile(models.Model): user = models.OneToOneField(settings.AUTH_USER_MODEL) # ... subjects = models.ManyToManyField(Subject, null=True, blank=True) After class UserProfile(models