many-to-many

(Django) How to reference through multiple layers of relationships?

别来无恙 提交于 2020-07-23 06:39:06
问题 The following is for a creative writing app. All aspects (characters, scenes, projects etc.) are recorded in the same model to allow for a simple sidebar directory. Each have extension models to add specific fields, so when an element is selected in the sidebar, the extension model is loaded as a form on the right. Extension model additional fields and universe model excluded for clarity. The problem is, I'm really stuck with restricting choices on a specific ManytoMany field. MODELS.PY class

update for manytomany field

百般思念 提交于 2020-06-23 12:51:08
问题 i want to to update field whenever an instance been created i tried signals but it seems complicate to ManyToManyField class MobileCustomer(models.Model): customer = models.CharField(max_length=30) phone = models.CharField(max_length=13) mobile = models.ManyToManyField(MobileStorage,through='SelectMobile') class SelectMobile(models.Model): mobile = models.ForeignKey(MobileStorage,on_delete=models.CASCADE) item = models.ForeignKey(MobileCustomer,on_delete=models.CASCADE) quantity = models

update for manytomany field

若如初见. 提交于 2020-06-23 12:50:25
问题 i want to to update field whenever an instance been created i tried signals but it seems complicate to ManyToManyField class MobileCustomer(models.Model): customer = models.CharField(max_length=30) phone = models.CharField(max_length=13) mobile = models.ManyToManyField(MobileStorage,through='SelectMobile') class SelectMobile(models.Model): mobile = models.ForeignKey(MobileStorage,on_delete=models.CASCADE) item = models.ForeignKey(MobileCustomer,on_delete=models.CASCADE) quantity = models

In FactoryBoy, how do I set a many-to-many field in my factory?

痴心易碎 提交于 2020-06-17 09:34:06
问题 I'm using Django 2.2 and FactoryBoy to attempt to create some factories to produce the following models ... class CoopType(models.Model): name = models.CharField(max_length=200, null=False) objects = CoopTypeManager() class Meta: # Creates a new unique constraint with the `name` field constraints = [models.UniqueConstraint(fields=['name'], name='coop_type_unq')] class Coop(models.Model): objects = CoopManager() name = models.CharField(max_length=250, null=False) types = models.ManyToManyField

Update many-to-many field in django with field name in variable

人走茶凉 提交于 2020-05-18 05:28:08
问题 I want to be able to update a many-to-many field on a model, when the name of the field is stored in a variable. This is relatively easy for a normal field (with kwargs in the constructor), or even a foreign key, but not so for a many-to-many field. Here's the situation: class Book(models.Model): title = models.CharField(max_length=30) authors = models.ManyToManyField(Author) field_name = 'title' new = Book(**{field_name:'My Book'}) # This sets title to mybook new.save() my_authors = Author

Laravel relations with composite foreign keys

时间秒杀一切 提交于 2020-05-17 08:46:40
问题 Here's what I want to achieve, we have Staff and every staff can have one Position for a department, as well as one Designation for a department and multiple Additional Charges for multiple departments, one department per Additional Charge . And I want to store all the responsibilities in the staff_responsibilities table I have a staff table with the following columns id name email Then I have staff_responsibilities table with the following columns: staff_id designation_id department_id

Get all table names in a Django app

安稳与你 提交于 2020-05-07 10:32:53
问题 How to get all table names in a Django app? I use the following code but it doesn't get the tables created by ManyToManyField from django.db.models import get_app, get_models app = get_app(app_name) for model in get_models(app): print model._meta.db_table 回答1: from django.db import connection tables = connection.introspection.table_names() seen_models = connection.introspection.installed_models(tables) As seen in the syncdb command for manage.py. In a comment below, years after the answer

Get all table names in a Django app

点点圈 提交于 2020-05-07 10:31:31
问题 How to get all table names in a Django app? I use the following code but it doesn't get the tables created by ManyToManyField from django.db.models import get_app, get_models app = get_app(app_name) for model in get_models(app): print model._meta.db_table 回答1: from django.db import connection tables = connection.introspection.table_names() seen_models = connection.introspection.installed_models(tables) As seen in the syncdb command for manage.py. In a comment below, years after the answer

How to access generated table fields in Django manytomanyfield

六月ゝ 毕业季﹏ 提交于 2020-02-25 04:32:27
问题 py which looks like below class Scenes(models.Model): name = models.CharField(max_length=30) def __str__(self): return self.name class Tech(models.Model): tech = models.CharField(max_length=30) scenario = models.ManyToManyField('Scenes') def __str__(self): return self.tech class UserLog(models.Model): tech_id = models.ForeignKey(Tech, on_delete=models.CASCADE) ....#other fields It generates one extra table called pages_tech_scenario (pages is my app name) My populated tables in database

JPA: Circular relations: diff between EclipseLink and Hiberante

Deadly 提交于 2020-02-23 06:31:34
问题 We have an entity Role which could be either users or groups. In the groups we have set permissions. Therefore a user belongs to a group. Additionally groups can belong to other groups, i.e. one could make a hierarchy of permissions. The idea is to store the relations from e.g. user -> group into a separate db table role_ref . @Table(name = "role__parent") @IdClass(RoleAssociationKey.class) @Data public class RoleAssociation implements Serializable { @Id @JoinColumn(name = "has_parent_role_id