django-models

Django - multiple models in one page

谁说我不能喝 提交于 2020-01-16 20:58:35
问题 I have a model that looks like this: models.py class BHA_List(models.Model): well = models.ForeignKey(WellInfo, 'CASCADE', related_name='bha_list') bha_number = models.CharField(max_length=100) class BHA_Drill_Bit(models.Model): bha_number = models.ForeignKey(BHA_List, 'CASCADE', related_name='bha_drill_bit') bit_type = models.CharField(max_length=111) class BHA_overall(models.Model): bha_number = models.ForeignKey(BHA_List, 'CASCADE', related_name='bha_overall') drill_str_name = models

Django - multiple models in one page

不羁的心 提交于 2020-01-16 20:57:48
问题 I have a model that looks like this: models.py class BHA_List(models.Model): well = models.ForeignKey(WellInfo, 'CASCADE', related_name='bha_list') bha_number = models.CharField(max_length=100) class BHA_Drill_Bit(models.Model): bha_number = models.ForeignKey(BHA_List, 'CASCADE', related_name='bha_drill_bit') bit_type = models.CharField(max_length=111) class BHA_overall(models.Model): bha_number = models.ForeignKey(BHA_List, 'CASCADE', related_name='bha_overall') drill_str_name = models

Annotating a FilteredRelation on a ManyToManyField returns nothing

落花浮王杯 提交于 2020-01-16 19:32:09
问题 Models class User(AbstractUser): pass class Report(Model): user = ForeignKey ( "User", related_name="reports" ) shared_doctors = ManyToManyField ( "User", symmetrical = False, related_name="shared_reports" ) I have more fields on the models, but I have omitted them in the interest of shortening the problem. Query User.objects.annotate( shared_reports_user = FilteredRelation( 'shared_reports', condition = Q(shared_reports__user=user) ) ).annotate( shared_reports_user_count = Count('shared

How exactly do I have to use HStoreField?

自闭症网瘾萝莉.ら 提交于 2020-01-16 19:22:17
问题 I'm using the latest version of Django and DRF. But after running it I'm getting this error: class HStoreDescriptor(models.fields.subclassing.Creator): AttributeError: module 'django.db.models.fields' has no attribute 'subclassing' I'm not sure how to use HStoreField and create an extension using migration. This is my structure of the file. webhook10/ |-- tutorial/ | |-- slack/ | | |-- migrations/ | | | +-- __init__.py | | |-- __init__.py | | |-- admin.py | | |-- apps.py | | |-- models.py | |

How to add Search bar for django template?

怎甘沉沦 提交于 2020-01-16 19:18:29
问题 I need a search bar in my template on top of my table. The search bar should search based on any table parameter, and filter the enteries accordingly. I implemented the search bar using CSS classes and I get it as I wanted. Now here's the views.py code. def jobs(request): jobs = Jobb.objects.all() search_term = '' if 'search' in request.GET: search_term = request.GET['search'] jobs = jobs.filter(position__icontains=search_term) context = { 'jobs': jobs, 'search_term': search_term, 'job':

How to add Search bar for django template?

痴心易碎 提交于 2020-01-16 19:18:08
问题 I need a search bar in my template on top of my table. The search bar should search based on any table parameter, and filter the enteries accordingly. I implemented the search bar using CSS classes and I get it as I wanted. Now here's the views.py code. def jobs(request): jobs = Jobb.objects.all() search_term = '' if 'search' in request.GET: search_term = request.GET['search'] jobs = jobs.filter(position__icontains=search_term) context = { 'jobs': jobs, 'search_term': search_term, 'job':

Many to Many relationships in Django

五迷三道 提交于 2020-01-16 19:13:08
问题 I am working on a design for some models in Django and wanted to get some advice. I have a model for teams, of which many users can be a part of. The users can also be members of many teams, but they cannot be members of the same team twice. There is also separate information I want to track for each team/user combo. On top of that, there will be a user who is an "admin" for each team, but each team may have only a single admin. I have some condensed data model definitions as follows: class

Many to Many relationships in Django

喜欢而已 提交于 2020-01-16 19:12:26
问题 I am working on a design for some models in Django and wanted to get some advice. I have a model for teams, of which many users can be a part of. The users can also be members of many teams, but they cannot be members of the same team twice. There is also separate information I want to track for each team/user combo. On top of that, there will be a user who is an "admin" for each team, but each team may have only a single admin. I have some condensed data model definitions as follows: class

Django get count on a ForeignKey

雨燕双飞 提交于 2020-01-16 18:37:15
问题 I need to get the total count of all contacts that belong to a group , but from within the model called batch .... This will help explain models (not shown in full) class Batch(models.Model): #FK group = models.ForeignKey(Group, null=True, blank=True) class Group(models.Model): name = models.CharField(max_length=60) class Contact(models.Model): first_name = models.CharField(max_length=60) group = models.ForeignKey(Group) So within batch I want to do something like this.... def get_contact

How to display Django model data in HTML table?

别等时光非礼了梦想. 提交于 2020-01-16 13:13:05
问题 I have two models i.e Starttime and Stoptime that store the start time and stop time respectively. Right now, each registered user will have multiple instances of the start and stop time, like so: Name Start_time Stop_time Bobby Dec. 31, 2019, 5:39 a.m Dec. 31, 2019, 5:50 a.m Jan. 01, 2020, 9:00 a.m Jan. 01, 2020, 18:00 a.m Jan. 02, 2020, 6:00 a.m Jan. 02, 2020, 19:00 a.m ... ... Tina Dec. 31, 2019, 9:00 a.m Dec. 31, 2019, 10:00 a.m Dec. 31, 2019, 12:00 p.m Dec. 31, 2019, 15:00 p.m Jan. 01,