many-to-many

SQLAlchemy cannot find referenced table via foreignkey in many-to-many relationship

SQLAlchemy cannot find referenced table via foreignkey in many-to-many relationship Question: I have already succeeded in adding one many-to-many relationship in my database. However, when trying to add another, I am met with: sqlalchemy.exc.NoReferencedTableError: Foreign key associated with column ‘user_shiftTemplate.template_id’ could not find table ‘shifttemplate’ with which to generate a foreign key to target column …

Total answers: 2

how ManyToManyField works?

how ManyToManyField works? Question: i made a genre field for my model in a music project ,i could use ForeignKey too pick genres in create section ,but in order to add another part(genres list) to site i used manytomany field since it works reverse ,i thought maybe i can add a genres part that when …

Total answers: 1

django queryset filter on whether related field is empty

django queryset filter on whether related field is empty Question: here is my models: class Flag(models.Model): ban = models.ForeignKey(‘flags.Ban’, on_delete=models.CASCADE, related_name=’flags’) class Ban(models.Model): punished = models.BooleanField(default=None) Flag is triggered when user report some content. and they are summarised in to a Ban instance for administrator to verify. briefly, a ban can have many flags. there …

Total answers: 2

How can I define the ManyToManyField name in django?

How can I define the ManyToManyField name in django? Question: I have this relationship Class Item(models.Model): pass Class Category(models.Model): items = models.ManyToManyField(Item) I can define the field name as items for category and access it via category.items but I want to define a field name for Item too as item.categories rather than the default item.category …

Total answers: 3

Django — concatenate filter on a many_to_many relation create unexpected join

Django — concatenate filter on a many_to_many relation create unexpected join Question: class ProductionOrderProductionOrderStatus(sf_models.BaseModel): production_order = models.ForeignKey(ProductionOrder, on_delete=models.CASCADE) production_order_status = models.ForeignKey(ProductionOrderStatus, on_delete=models.CASCADE) class ProductionOrderStatus(sf_models.BaseModel): status = models.IntegerField(null=False) begin_datetime = models.DateTimeField(default=timezone.now) end_datetime = models.DateTimeField(null=True, blank=True) class ProductionOrder(sf_models.BaseModel): statuses = models.ManyToManyField(ProductionOrderStatus, through=’ProductionOrderProductionOrderStatus’, related_name=’production_orders’) if i concatenate 2 filter like this -> ProductionOrder.objects.filter(statuses__status=2).filter(statuses__end_datetime=None) i get this sql: ‘SELECT …

Total answers: 1

Django filter_horizontal – how to connect more fields together

Django filter_horizontal – how to connect more fields together Question: I need to connect more fields to one filter_horizontal parameter in Django Admin as string. I have three many-to-many variables: class EducationTypeAdmin(admin.ModelAdmin): … list_filter = ("qualifications", "school_levels", "subject_groups") filter_horizontal = ["qualifications", "subject_groups", "school_levels"] This code will make 3 seperate many-to-many horizontal filters. I need them …

Total answers: 1

create a django-queryset with all objects but not all related many to many fields by a condition

create a django-queryset with all objects but not all related many to many fields by a condition Question: class Post(models.Model): text = models.TextField() class Project(models.Model): name = models.CharField(max_length=60) description = models.CharField(max_length=500) class Tag(models.Model): name = models.CharField(max_length=60) project = models.ForeignKey(Project, on_delete=models.CASCADE) class TaggedPost(models.Model): org_post = models.ForeignKey(Post, on_delete=models.CASCADE) tags = models.ManyToManyField(Tag) Assumed I have defined above models. …

Total answers: 1

can't access to members of ManyToManyField

can't access to members of ManyToManyField Question: I want to get the products which are connect to my form like:[‘shirt’ , ‘hat’] but this gives me the bound method Manager insted of Queryset. models.py: from django.db import models from eshop_product.models import Product class Form(models.Model): user_name = models.CharField(max_length=600, null=True, blank=True) first_name = models.CharField(max_length=600, null=True, blank=True) products …

Total answers: 1

In how many ways, can I get ManyToMany field data using Django ORM?

In how many ways, can I get ManyToMany field data using Django ORM? Question: Let’s assume I have a model named A and B. In model B I have ManyToMany field to model A so in how many ways I can get data from model A using model B: class A(models.Model): name= models.CharField(…) class B(models.Model): …

Total answers: 2

lack of foreign key in admin model?

lack of foreign key in admin model? Question: I get the following error when trying to update my database: class ‘artdb.admin.RoleInline’: (admin.E202) ‘artdb.Role’ has no ForeignKey to ‘artdb.Person’ I want ot have a many to many relation between Person and Role model.py (not showing all classes): class Person(models.Model): mail=models.EmailField() firstName=models.CharField(max_length=200) lastName=models.CharField(max_length=200) phoneNumber=PhoneNumberField() streetAdress=models.CharField(max_length=200) zipcode=models.CharField(max_length=200) city=models.CharField(max_length=200,default="Göteborg") …

Total answers: 2